100 likes | 302 Views
Applications in Java 1.2. Half Text Half Graphics. Swing Components. Defined in package javax.swing Pure Java components AWT components tied to local platform GUI UNIX java windows look like X windows Windows java windows look like windows windows (??) etc.
E N D
Applications in Java 1.2 Half Text Half Graphics CS423 (cotter)
Swing Components • Defined in package javax.swing • Pure Java components • AWT components tied to local platform GUI • UNIX java windows look like X windows • Windows java windows look like windows windows (??) • etc. • Swing defines a common look and feel for Java. CS423 (cotter)
Swing Components • Derive from awt classes java.lang.Object -> java.awt.Component -> jav.awt.Container -> javax.swing.Jcomponent • Methods overloaded in swing to allow different behaviour CS423 (cotter)
Product.java / From Java: How to Program - Deitel and Deitel // Calculate the product of three integers import javax.swing.JOptionPane; public class Product { public static void main( String args[] ) { int x, y, z, result; String xVal, yVal, zVal; xVal = JOptionPane.showInputDialog( "Enter first integer:" ); yVal = JOptionPane.showInputDialog( "Enter second integer:" ); zVal = JOptionPane.showInputDialog( "Enter third integer:" ); CS423 (cotter)
Product.java x = Integer.parseInt( xVal ); y = Integer.parseInt( yVal ); z = Integer.parseInt( zVal ); result = x * y * z; JOptionPane.showMessageDialog( null, "The product is " + result ); System.exit( 0 ); } } CS423 (cotter)
Product Output(s) CS423 (cotter)
JOptionPane • Similar to windows message boxes • Types of Option Panes: showConfirmDialog(null,message,title,optionType,msgType); Asks a confirming question, like yes/no/cancel. showInputDialog(message); Prompt for some input. showMessageDialog(null, message); Tell the user about something that has happened. showOptionDialog(....); The Grand Unification of the above three. CS423 (cotter)
OptionType • DEFAULT_OPTION • YES_NO_OPTION • YES_NO_CANCEL_OPTION • OK_CANCEL_OPTION CS423 (cotter)
messageType • ERROR_MESSAGE • INFORMATION_MESSAGE • WARNING_MESSAGE • QUESTION_MESSAGE • PLAIN_MESSAGE CS423 (cotter)