Download presentation
Presentation is loading. Please wait.
Published byFelicity O’Connor’ Modified over 9 years ago
1
1/23: Java Modular Components Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component: the JOptionPane.
2
Identifiers: How to Name. Must start with a lowercase non-number –but classes must start with a capitalized non-number Can contain alphas (letters), numbers, underscores, dollar signs –acceptable: $dinero value$2 g my_debt Cannot contain other symbols or spaces –unacceptable: a*b Value2 2nd my cost @sum Cannot be a Java keyword –EX: static void class private import
3
Outside the MS-DOS Window Most programs today work in a “Windows”-type environment, not a MS-DOS window. Dialog boxes: informational, request input, show output, give warnings, etc. In Java, we use the JOptionPane.
4
Welcome4.java // Fig. 2.6: Welcome4.java (pg. 66) //Java extension packages – import JOptionPane import javax.swing.JOptionPane; public class Welcome4 { //main method begins execution of app public static void main ( String args[] ) { JOptionPane.showMessageDialog ( null, “Welcome\nto\nJava\nProgramming!” ); System.exit ( 0 ); } comments import statement class header method header statement
5
JOptionPane: A Dialog Box must import javax.swing.JOptionPane before defining the class. –a library of objects & methods for dialog boxes Usage: a statement like this: JOptionPane.showMessageDialog( null,“Words” ); to get
6
JOptionPane: Variations The third parameter varies the title bar string: JOptionPane.showMessageDialog ( null, “Words”, “Title Here”, JOptionPane.INFORMATION_MESSAGE) –Replaces the Message header with Title Here. More info available at http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.htmlhttp://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.html Title Here
7
JOptionPane: Variations The last parameter varies the icon shown in the box: JOptionPane.showMessageDialog( null,“Word”,“Title”, … JOptionPane.PLAIN_MESSAGE –JOptionPane.ERROR_MESSAGE –JOptionPane.INFORMATION_MESSAGE –JOptionPane.WARNING_MESSAGE –JOptionPane.QUESTION_MESSAGE More info available at http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.htmlhttp://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.html
8
JOptionPane.showInputDialog A dialog box that allows the user to input a String. EX: JOptionPane.showInputDialog ( “Please type your name” ); Learn more at http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.htmlhttp://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JOptionPane.html
9
Program of the Day: pg. 69 Pg. 69: Addition.java –Pay attention to the use of the dialog boxes. Friday: –Finish Addition.java –Getting comfortable with Dialog Boxes Monday: –Addition.java in depth –Getting values from the user –Strings vs. integers and other primitive data types –Arithmetic operators
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.