Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
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.
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 // Fig. 2.6: Welcome4.java (pg. 66)
//Java extension packages – import JOptionPane
import
import javax.swing.JOptionPane;
statement
class
header
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 );
}
method
header
statement
statement
}
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
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.
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. 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