{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture06 - Computer Science 65 Intro to CS Dialog Boxes...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
Announcements Homework #3 due Thursday
Image of page 2
Image of page 3

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

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

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

View Full Document Right 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.
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;
Image of page 7

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

View Full Document Right Arrow Icon
Message Dialogs & Input Dialogs 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”);
Image of page 8
Image of page 9

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

View Full Document Right Arrow Icon
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?
Image of page 11

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

View Full Document Right 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.”
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");
Image of page 13

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

View Full Document Right Arrow Icon
Converting String Input to Numbers Java contains several methods that can covert Strings to numbers
Image of page 14
notes
Image of page 15

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

View Full Document Right Arrow Icon
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
Image of page 17

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

View Full Document Right Arrow Icon
If Statement Style Bad vs. Good Bad!!
Image of page 18
Image of page 19
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern