lecture06 - Computer Science 65 Intro to CS February 12,...

Info iconThis preview shows pages 1–19. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science 65 Intro to CS February 12, 2008 Dialog Boxes If-Else Statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements Homework #3 due Thursday
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Dialog Boxes A dialog box is a small graphical window that displays a message or requests input
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dialog Boxes Two types of the dialog boxes: ________________ - a dialog box that displays a message. ________________ - a dialog box that prompts the user for input.
Background image of page 6
Dialog Boxes with Java Dialog boxes use the class JOptionPane, which is not automatically available to Java programs. Near the beginning of the file (before the class header) you must include import javax.swing.JOptionPane;
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JOptionPane.showMessageDialog(null , “Hello World”); The first argument, null, is only important to other programs the display other graphical windows Input dialogs return a string to the program. Easy way to get input from the user String name; name = JOptionPane.showInputDialog(null,“Enter name”);
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
What if you want a number? showInputDialog only returns a String How would I get a number from the user using a dialog box? int value; value = JOptionPane. showInputDialog (null,"Enter a number"); //syntax error? Why?
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Parse Methods ____________________ contain methods that convert a string to a number Examples Integer Double The Integer class has a method that converts a string to an int , The Double class has a method that converts a string to a double These methods are known as parse methods because their names begin with the word “parse.”
Background image of page 12
The Parse Methods // Store 2599 in iVar. int iVar = Integer.parseInt("2599"); // Store 7945.6 in dVar. double dVar = Double.parseDouble("7945.6");
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Converting String Input to Numbers Java contains several methods that can covert Strings to numbers
Background image of page 14
notes
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 16
If Statement Style If an if statement does not have the block curly braces, only the next statement is part of the if statement if ( expression ) statement ; It’s good programming style to always use curly braces when using if statements
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bad vs. Good Bad!! if (
Background image of page 18
Image of page 19
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/02/2008 for the course CS 065 taught by Professor Urness during the Spring '08 term at Drake University .

Page1 / 48

lecture06 - Computer Science 65 Intro to CS February 12,...

This preview shows document pages 1 - 19. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online