90 likes | 230 Views
1/20: Java Modular Components. Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component: the JOptionPane. Identifiers: How to Name. Must start with a lowercase non-number but classes must start with a capitalized non-number
E N D
1/20: Java Modular Components • Identifiers: naming requirements for Java variables & objects • Stepping out of the MS-DOS window: • The Java Modular Component: the JOptionPane.
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
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.
Welcome4.java comments import statement class header method header statement statement // Fig. 2.6: Welcome4.java (pg. 44) // Printing multiple lines in a dialog box import javax.swing.JOptionPane; public class Welcome4 { public static void main ( String args[] ) { JOptionPane.showMessageDialog ( null , “Welcome\nto\nJava\nProgramming!” ); System.exit ( 0 ); } }
JOptionPane: A Dialog Box • must import javax.swing.JOptionPane before defining the class. • a library of objects & methods for dialog boxes • usage: • JOptionPane.showMessageDialog ( null , “Words” );to get
JOptionPane: Variations • The third parameter varies the title bar string: JOptionPane.showMessageDialog ( null, “Words”, “Title Here”,JOptionPane.PLAIN_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.html
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.html
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.html
Program of the Day: pg. 47 • Pg. 47: Addition.java • Pay attention to the use of the dialog boxes. • Next time: • Addition.java in depth • Getting values from the user. • Strings vs. integers and other primitive data types • Arithmetic operators • Next Thursday: 1st quiz – 30 min.