Applications in Java 1 2 Half Text Half









- Slides: 9
Applications in Java 1. 2 Half Text Half Graphics CSTP FS 99 CS 423 (cotter) 1
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 (? ? ) – etc. • Swing defines a common look and feel for Java. CSTP FS 99 CS 423 (cotter) 2
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 CSTP FS 99 CS 423 (cotter) 3
Product. java / From Java: How to Program - Deitel and Deitel // Calculate the product of three integers import javax. swing. JOption. Pane; public class Product { public static void main( String args[] ) { int x, y, z, result; String x. Val, y. Val, z. Val; x. Val = JOption. Pane. show. Input. Dialog( "Enter first integer: " ); y. Val = JOption. Pane. show. Input. Dialog( "Enter second integer: " ); z. Val = JOption. Pane. show. Input. Dialog( "Enter third integer: " ); CSTP FS 99 CS 423 (cotter) 4
Product. java x = Integer. parse. Int( x. Val ); y = Integer. parse. Int( y. Val ); z = Integer. parse. Int( z. Val ); result = x * y * z; JOption. Pane. show. Message. Dialog( null, "The product is " + result ); System. exit( 0 ); } } CSTP FS 99 CS 423 (cotter) 5
Product Output(s) CSTP FS 99 CS 423 (cotter) 6
JOption. Pane • Similar to windows message boxes • Types of Option Panes: show. Confirm. Dialog(null, message, title, option. Type, msg. Type); Asks a confirming question, like yes/no/cancel. show. Input. Dialog(message); Prompt for some input. show. Message. Dialog(null, message); Tell the user about something that has happened. show. Option. Dialog(. . ); The Grand Unification of the above three. 7
Option. Type • • DEFAULT_OPTION YES_NO_CANCEL_OPTION OK_CANCEL_OPTION CSTP FS 99 CS 423 (cotter) 8
message. Type • • • ERROR_MESSAGE INFORMATION_MESSAGE WARNING_MESSAGE QUESTION_MESSAGE PLAIN_MESSAGE CSTP FS 99 CS 423 (cotter) 9