• Identifiers: naming requirements for Java variables & objects
• Stepping out of the MS-DOS window:
• The Java Modular Component: the JOptionPane.
• 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
• 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.
comments
// Fig. 2.6: Welcome4.java (pg. 44)
// Printing multiple lines in a dialog box import statement import javax.swing.JOptionPane; class header method header statement statement
} public class Welcome4 { public static void main ( String args[] )
{
JOptionPane.showMessageDialog ( null ,
“Welcome\nto\nJava\nProgramming!” );
System.exit ( 0 );
}
• must import javax.swing.JOptionPane before defining the class.
– a library of objects & methods for dialog boxes
• usage:
– JOptionPane.showMessageDialog ( null , “Words” ); to get
• 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
• 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
• 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
• 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
• Tomorrow: 1 st quiz – 30 min.