Chapter II Part II

Chapter II Part II - IT108 Chapter Two Part II George Mason...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: IT108 Chapter Two, Part II George Mason University JOptionPane Class for GUI Input • Message boxes accept input through graphical interface • Two dialog boxes accepting input • InputDialog: prompts the user for text input • ConfirmDialog: query followed by Yes, No, and Cancel Using Input Dialog Boxes • Input dialog box: asks question above response field • showInputDialog( ) used to create input dialog boxes • Six overloaded versions of showInputDialog ( ) • Simple version takes prompt, returns string • result = JOptionPane.showInputDialog (“prompt"); Note: you must DO something with the String result Example Example Example • Version of showInputDialog ( ) using four arguments • Parent component (background screen or frame) • Message the user will see before entering a value • Title to be displayed in title bar of the input dialog box • A class field describing the type of dialog box • Example: JOptionPane.showInputDialog (null, " What is your area code?:", "Area code information", JOptionPane.QUESTION_MESSAGE); Input Dialog Boxes Example Type-wrapper classes for each primitive in java.lang • convert string input to primitive type • Two type-wrapper classes: Integer and Double Converting string to a double type • weeklyPay = Double.parseDouble(wageString) * hoursInWeek; Converting string to integer type • dependents = Integer.parseInt(dependentsString); Input Dialog Boxes Example Confirm Dialog Boxes Confirm dialog box displays options Yes, No, Cancel • Implement with showConfirmDialog( ) • Four overloaded versions of the method are available Basic showConfirmDialog ( ) takes two arguments • Parent component (which can be null) • String prompt that is displayed in the box showConfirmDialog( ) method returns integer value Ex: selection = JOptionPane.showConfirmDialog(null, "Do you want to upgrade to first class?"); Example Example Example to Trace • SalaryDialog.java • GUIExample.java import javax.swing.JOptionPane; public class SalaryDialog { public static void main(String args) { String wageString, dependentsString; double wage, weeklyPay; int dependents; double hoursinWeek = 37.5; wageString = JOptionPane.showInputDialog(null, "Enter employee's hourly wage“ , "Salary dialog 1", JOptionPane.INFORMATION_MESSAGE); , "Salary dialog 1", JOptionPane....
View Full Document

This note was uploaded on 01/26/2012 for the course IT 108, 103, taught by Professor Bruno during the Spring '11 term at George Mason.

Page1 / 44

Chapter II Part II - IT108 Chapter Two Part II George Mason...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online