tailieunhanh - Lecture Software construction - Lab 7: Java programming with SWING GUI builder

In this chapter, the following content will be discussed: Simplest GUI programming: JOptionPane; types of joptionpanes; onscreen GUI elements, swing component hierarchy, Java GUI, methods of all swing components, more JComponent methods. | Software Construction LAB 07 Java Programming with SWING GUI Builder Simplest GUI programming: JOptionPane An option pane is a simple dialog box for graphical input/output advantages: simple flexible (in some ways) looks better than the black box of death disadvantages: created with static methods; not very object-oriented not very powerful (just simple dialog boxes) Types of JOptionPanes public static void showMessageDialog( Component parent, Object message) Displays a message on a dialog with an OK button. public static int showConfirmDialog( Component parent, Object message) Displays a message and list of choices Yes, No, Cancel public static String showInputDialog( Component parent, Object message) Displays a message and text field for input, and returns the value entered as a String. JOptionPane examples 1 showMessageDialog analogous to for displaying a simple message import .*; class MessageDialogExample { public static void . | Software Construction LAB 07 Java Programming with SWING GUI Builder Simplest GUI programming: JOptionPane An option pane is a simple dialog box for graphical input/output advantages: simple flexible (in some ways) looks better than the black box of death disadvantages: created with static methods; not very object-oriented not very powerful (just simple dialog boxes) Types of JOptionPanes public static void showMessageDialog( Component parent, Object message) Displays a message on a dialog with an OK button. public static int showConfirmDialog( Component parent, Object message) Displays a message and list of choices Yes, No, Cancel public static String showInputDialog( Component parent, Object message) Displays a message and text field for input, and returns the value entered as a String. JOptionPane examples 1 showMessageDialog analogous to for displaying a simple message import .*; class MessageDialogExample { public static void main(String[] args) { (null, "How's the weather?"); (null, "Second message"); } } JOptionPane examples 2 showConfirmDialog analogous to a that prints a question, then reading an input value from the user (can only be one of the provided choices) import .*; class ConfirmDialogExample { public static void main(String[] args) { int choice = (null, "Erase your hard disk?"); if (choice == ) { (null, "Disk erased!"); } else { (null, "Cancelled."); } } } JOptionPane examples 3 showInputDialog analogous to a that prints a question, then reading an input value from the user (can be any value) import .*; class InputDialogExample { public static void main(String[] args) { String name = (null, "What's yer name, pardner?"); .