1 / 9

1/20: Java Modular Components

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

nida
Download Presentation

1/20: Java Modular Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  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 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 ); } }

  5. 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

  6. 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

  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.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.html

  9. 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.

More Related