Object-Oriented Programming 10

955 views

Published on

GUI and Event

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
955
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object-Oriented Programming 10

  1. 1. CHAPTER 10GUI & EVENTHANDLINGMr.Warawut Khangkhane-Mail: awarawut@hotmail.comSocial Media: www.facebook.com/AjWarawut
  2. 2. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling GUI 2
  3. 3. GUI Mr.Warawut Khangkhan F F F F F ʽ F Graphic User Interface Chapter 10 GUI & Event Handling(GUI) F java.awtjavax.swing 3
  4. 4. GUI COMPONENT Mr.Warawut Khangkhan F F F F ʽ F F F AWT Set Chapter 10 GUI & Event Handling(Abstract Windowing Toolkit)Swing Set 4
  5. 5. GUI COMPONENT Mr.Warawut Khangkhan F GUI F3 F F Chapter 10 GUI & Event HandlingContainer ˈ F F ˈ AbstractClass F F2 Top Level F F ˈ F Frame Dialog Non-Top Level F F F ˈ F Panel Scroll Pane 5
  6. 6. GUI COMPONENT Mr.Warawut Khangkhan F GUI F3 F F Chapter 10 GUI & Event HandlingSimple ComponentButton, Label, RadioButton, List Pane ComboBox ˈ FText Component F F F TextField ˈ F 6
  7. 7. GUI: FRAME Mr.Warawut KhangkhanFrame: F ˈ F Top-Level Chapter 10 GUI & Event HandlingContainer F JFrame F F Swing Set F ˁ F F F ˈ GUI F F F 1 ˈ F 7
  8. 8. GUI: FRAME Mr.Warawut KhangkhanJFrame frameName = new JFrame(title); Chapter 10 GUI & Event HandlingframeName ˈ F JFrametitle ˈ F F F 8
  9. 9. ʽ F ˆ FsetDefaultCloseOperation( ) Mr.Warawut Khangkhan• DO_NOTHING_ON_CLOSE F F• HIDE_ON_CLOSE ˈ F F F F F F F F F F Chapter 10 GUI & Event Handling F• DISPOSE_ON_CLOSE ˈ F F F F F F F F F• EXIT_ON_CLOSE ˈ ʽ F ˆ F System.exit(0) 9
  10. 10. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 10
  11. 11. GUI: PANEL Mr.Warawut KhangkhanPanel: F ˈ F Top-Level Chapter 10 GUI & Event HandlingContainer F JPanel ˈ F F Container FFrame ˈ F 11
  12. 12. GUI: PANEL Mr.Warawut KhangkhanJPanel pName = new JPanel( ); or Chapter 10 GUI & Event HandlingJPanel pName = new JPanel(manager);pName ˈ F JPanelmanager ˈ LayoutManager F F Panel Default LayoutManger ˈ Flow Layout ˈ F F F F F 12
  13. 13. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 13
  14. 14. GUI: BUTTON Mr.Warawut Khangkhan Button ˈ ˁ F F JButton Chapter 10 GUI & Event HandlingJButton buttonName = new JButton(text); orJButton buttonName = new Jbutton(text, icon);buttonName ˈ F JButtontext ˈ F F F ˁ 14icon ˈ F F ˁ
  15. 15. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 15
  16. 16. Example: Ch10_04GUI: LABEL Mr.Warawut Khangkhan Label ˈ F F F ˈ F F JLabel Chapter 10 GUI & Event HandlingJLabel lname = new Jlabel(text, icon, Alignment);lName ˈ F JLabeltext ˈ F F F Labelicon ˈ F F LabelAlignment ˈ F Label - SwingConstans.LEFT F 16 - SwingConstants.CENTER - SwingConstants.RIGHT
  17. 17. GUI: TEXTFIELD Mr.Warawut Khangkhan TextField ˈ F F F F F JTextField Chapter 10 GUI & Event HandlingJTextField textName = new JTextField(text, Length);textName ˈ F JTextFieldtext ˈ F F F TextFieldLength ˈ TextField 17
  18. 18. Example: Ch10_05GUI: PASSWORDFIELD Mr.Warawut Khangkhan PasswordField ˈ F F F F F F Chapter 10 GUI & Event Handling JPasswordFieldJPasswordField pw = new JPasswordField(text, Length);textName ˈ F JPasswordFieldtext ˈ F F F PasswordField 18Length ˈ F
  19. 19. GUI: RADIOBUTTON Mr.Warawut KhangkhanRadioButton ˈ F F F F Chapter 10 GUI & Event HandlingJRadioButton FButtonGroup F F F F F 19
  20. 20. GUI: RADIOBUTTON Mr.Warawut KhangkhanJRadioButton radioName = new JRadioButton(text, icon, Chapter 10 GUI & Event Handling boolValue);radioName ˈ F JRadioButtontext ˈ F F F RadioButtonicon ˈ F F RadioButtonboolValue ˈ F F ˈ true 20
  21. 21. GUI: RADIOBUTTON Mr.Warawut Khangkhanpublic ButtonGroup( ); Chapter 10 GUI & Event Handling add( ) remove( ) ButtonGroup 21
  22. 22. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 22 List F F F F F F F JList JScrollPane FGUI: LIST List ˈ F
  23. 23. GUI: LIST Mr.Warawut KhangkhanJList listName = new JList( ); or Chapter 10 GUI & Event HandlingJList listName = new JList(dataModel); orJList listName = new JList(items);listName ˈ F JListdataModel ˈ F F1 F 1items ˈ F Object 23 Vector
  24. 24. Example: Ch10_06GUI: SCROLLPANE Mr.Warawut Khangkhan ScrollPane ˈ F F Scroll bar F JScrollPane Chapter 10 GUI & Event HandlingJScrollPane panelist = new JScrollPane(listName);panelist ˈ F JScrollPanelistName ˈ F List 24
  25. 25. GUI: CHECKBOX Mr.Warawut Khangkhan CheckBox ˈ F F F F F Chapter 10 GUI & Event Handling JCheckBox ˈ true falseJCheckBox checkName = new JCheckBox(text, icon);checkName ˈ F JCheckBoxtext ˈ F F F CheckBox 25icon ˈ F F CheckBox
  26. 26. Example: Ch10_07GUI: COMBOBOX Mr.Warawut Khangkhan ComboBox ˈ F F F 1 F F Chapter 10 GUI & Event Handling 1 F F JComboBoxJComboBox comboName = new JComboBox(items);comboName ˈ F JComboBox 26items ˈ F Object Vector
  27. 27. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 27 F F F FF F F FGUI: MENU F F Menu ˈ F F
  28. 28. F MENU Mr.Warawut Khangkhan1. F F JMenuBarJMenuBar menubar = Chapter 10 GUI & Event Handling new JMenuBar( );2. F JMenuJMenu menuName = new JMenu(itemName);3. F F JMenuItemJMenuItem menuItemName = 28 new JMenuItem(subItemName);
  29. 29. Example: Ch10_08 F MENU Mr.Warawut Khangkhan4. F F Chapter 10 GUI & Event HandlingmenuName.add(menuItemName);5. F Fmenubar.add(menuName);6. F F Frame FsetJMenuBarframeName.setJMenuBar(menubar); 29
  30. 30. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling LAYOUT MANAGER 30
  31. 31. LAYOUT MANAGER Mr.Warawut Khangkhan F F Panel Default ˈ Chapter 10 GUI & Event Handling FlowLayout ˈ F F F F Layout F F F setLayout( )JPanel panel = new JPanel( ); 31panel.setLayout(new FlowLayout( ));
  32. 32. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 32 Example: Ch10_09FLOWLAYOUT MANAGER F F F F F ˈ
  33. 33. BORDERLAYOUTMANAGER Mr.Warawut Khangkhan ˈ F F ˈ 5 FNorth, South, East, West Chapter 10 GUI & Event HandlingCenter F F F1 F F F F F 1 F F F ˈ 5 F F Example: Ch10_10 33
  34. 34. GRIDLAYOUT MANAGER Mr.Warawut Khangkhan ˈ F F ˈ Grid F F Grid Chapter 10 GUI & Event Handling F1 F F F Example: Ch10_11 34
  35. 35. GRIDBAGLAYOUTMANAGER Mr.Warawut Khangkhan ˈ F F ˈ F F F GridLayout Chapter 10 GUI & Event HandlingManager F F F F 1 F F F 1 1 F F Example: Ch10_12 35
  36. 36. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling 10 EVENT HANDLING 36
  37. 37. Example: Ch10_13, Ch10_14 EVENT HANDLING Mr.Warawut Khangkhan ˈ F F ˈ F F ˈ Event Listener Chapter 10 GUI & Event Handling F F F ˈ ˁ CloseButton F ButtonListener F F F F ˈ Event Listener ˁ CloseButton 37buttonName.addActionListener(new ButtonListener( ));

×