Object-Oriented Programming 10
Upcoming SlideShare
Loading in...5
×
 

Object-Oriented Programming 10

on

  • 763 views

GUI and Event

GUI and Event

Statistics

Views

Total Views
763
Views on SlideShare
763
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Object-Oriented Programming 10 Object-Oriented Programming 10 Presentation Transcript

  • CHAPTER 10GUI & EVENTHANDLINGMr.Warawut Khangkhane-Mail: awarawut@hotmail.comSocial Media: www.facebook.com/AjWarawut
  • Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling GUI 2
  • GUI Mr.Warawut Khangkhan F F F F F ʽ F Graphic User Interface Chapter 10 GUI & Event Handling(GUI) F java.awtjavax.swing 3
  • 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
  • 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
  • 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
  • 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
  • GUI: FRAME Mr.Warawut KhangkhanJFrame frameName = new JFrame(title); Chapter 10 GUI & Event HandlingframeName ˈ F JFrametitle ˈ F F F 8
  • ʽ 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
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 10
  • GUI: PANEL Mr.Warawut KhangkhanPanel: F ˈ F Top-Level Chapter 10 GUI & Event HandlingContainer F JPanel ˈ F F Container FFrame ˈ F 11
  • 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
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 13
  • 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 ˁ
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 15
  • 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
  • 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
  • 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
  • GUI: RADIOBUTTON Mr.Warawut KhangkhanRadioButton ˈ F F F F Chapter 10 GUI & Event HandlingJRadioButton FButtonGroup F F F F F 19
  • 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
  • GUI: RADIOBUTTON Mr.Warawut Khangkhanpublic ButtonGroup( ); Chapter 10 GUI & Event Handling add( ) remove( ) ButtonGroup 21
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 22 List F F F F F F F JList JScrollPane FGUI: LIST List ˈ F
  • 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
  • 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
  • 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
  • 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
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 27 F F F FF F F FGUI: MENU F F Menu ˈ F F
  • 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);
  • 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
  • Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling LAYOUT MANAGER 30
  • 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( ));
  • Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 32 Example: Ch10_09FLOWLAYOUT MANAGER F F F F F ˈ
  • 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
  • GRIDLAYOUT MANAGER Mr.Warawut Khangkhan ˈ F F ˈ Grid F F Grid Chapter 10 GUI & Event Handling F1 F F F Example: Ch10_11 34
  • 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
  • Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling 10 EVENT HANDLING 36
  • 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( ));