Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Fundamentals of computing 1: Lecture 14 - Duy Tan University

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Lecture Fundamentals of computing 1: Lecture 14 introduce Graphic User Interface (GUI). This chapter presents the following content: Graphic User Interface (GUI), Jframe, event-driven programming, layout manager, components, mouse events, keyboard events, 2D graphics, animation with timers. | Lecture Title: Graphic User Interface (GUI) Fundamentals of Computing 1 Agenda JOptionPane Graphic User Interface (GUI) JFrame Event-Driven Programming Layout Manager Components Mouse events Keyboard events 2D Graphics Animation with Timers ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) 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) Graphical input and output with JOptionPane Types of JOptionPanes showMessageDialog(, ) Displays a message on a dialog with an OK button. showConfirmDialog(, ) Displays a message and list of choices Yes, No, Cancel; returns user's choice as an int with one of the following values: JOptionPane.YES_OPTION JOptionPane.NO_OPTION JOptionPane.CANCEL_OPTION showInputDialog(, ) Displays a message and text field for input; returns the user's value entered as a String. NOTE: can pass null for the parent to all methods JOptionPane examples 1 showMessageDialog analogous to System.out.println to display a message import javax.swing.*; public class MessageDialogExample { public static void main(String[] args) { JOptionPane.showMessageDialog(null,"How's the weather?"); JOptionPane.showMessageDialog(null, "Second message"); } } JOptionPane examples 2 showConfirmDialog analogous to a System.out.print that prints a question, then reading an input value from the user (can only be one of the provided choices) import javax.swing.*; public class ConfirmDialogExample { public static void main(String[] args) { int choice = JOptionPane.showConfirmDialog(null, "Erase your hard disk?"); if (choice == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, "Disk erased!"); } else { JOptionPane.showMessageDialog(null, "Cancelled."); } } } . | Lecture Title: Graphic User Interface (GUI) Fundamentals of Computing 1 Agenda JOptionPane Graphic User Interface (GUI) JFrame Event-Driven Programming Layout Manager Components Mouse events Keyboard events 2D Graphics Animation with Timers ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) 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) Graphical input and output with JOptionPane Types of JOptionPanes showMessageDialog(, ) Displays a message on a dialog with an OK button. showConfirmDialog(, ) Displays a message and list of choices Yes, No, Cancel; returns user's choice as an int with one of the following values: JOptionPane.YES_OPTION JOptionPane.NO_OPTION JOptionPane.CANCEL_OPTION .