SlideShare a Scribd company logo
1 of 37
Download to read offline
CHAPTER 10
GUI & EVENT
HANDLING
Mr.Warawut Khangkhan
e-Mail: awarawut@hotmail.com
Social 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.awt
javax.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 Handling
Container
 ˈ F              F                  ˈ    Abstract
Class                 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 Handling
Simple Component
Button, Label, RadioButton, List       Pane
     ComboBox     ˈ F
Text Component               F         F
 F   TextField   ˈ F

                                               6
GUI: FRAME




                                    Mr.Warawut
                                     Khangkhan
Frame: F
 ˈ        F     Top-Level




                                        Chapter 10 GUI & Event Handling
Container F          JFrame
   F    F    Swing Set
      F                   ˁ F
            F F         ˈ GUI   F
     F F 1       ˈ F
                                    7
GUI: FRAME




                                        Mr.Warawut
                                         Khangkhan
JFrame frameName = new JFrame(title);




                                            Chapter 10 GUI & Event Handling
frameName     ˈ          F       JFrame
title         ˈ F    F       F




                                        8
ʽ                       F   ˆ F
setDefaultCloseOperation( )




                                                                         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
                                 Khangkhan
Panel: F
 ˈ        F     Top-Level




                                  Chapter 10 GUI & Event Handling
Container     F      JPanel ˈ
      F F       Container F
Frame ˈ F


                                11
GUI: PANEL




                                                            Mr.Warawut
                                                             Khangkhan
JPanel pName = new JPanel( );
    or




                                                              Chapter 10 GUI & Event Handling
JPanel pName = new JPanel(manager);
pName            ˈ           F            JPanel
manager          ˈ               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 Handling
JButton buttonName = new JButton(text);
     or
JButton buttonName = new Jbutton(text,
                             icon);
buttonName     ˈ         F
              JButton
text             ˈ F   F       F       ˁ   14

icon              ˈ  F     F       ˁ
Mr.Warawut
             Chapter 10 GUI & Event Handling
 Khangkhan
                                               15
Example: Ch10_04
GUI: LABEL




                                                                        Mr.Warawut
                                                                         Khangkhan
  Label ˈ F              F                   F
   ˈ      F      F                               JLabel




                                                                          Chapter 10 GUI & Event Handling
JLabel lname = new Jlabel(text, icon,
               Alignment);
lName    ˈ                           F                  JLabel
text       ˈ F                   F               F     Label
icon        ˈ        F                   F           Label
Alignment ˈ                  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 Handling
JTextField textName =
          new JTextField(text, Length);
textName ˈ             F          JTextField
text     ˈ F       F       F    TextField
Length    ˈ                    TextField
                                               17
Example: Ch10_05

GUI: PASSWORDFIELD




                                             Mr.Warawut
                                              Khangkhan
 PasswordField ˈ             F
   F    F   F F  F




                                               Chapter 10 GUI & Event Handling
 JPasswordField
JPasswordField pw =
    new JPasswordField(text, Length);
textName ˈ         F
              JPasswordField
text      ˈ F    F   F
              PasswordField                  18


Length     ˈ           F
GUI: RADIOBUTTON




                                            Mr.Warawut
                                             Khangkhan
RadioButton ˈ           F           F
            F               F




                                              Chapter 10 GUI & Event Handling
JRadioButton    F
ButtonGroup         F           F       F
 F F


                                            19
GUI: RADIOBUTTON




                                              Mr.Warawut
                                               Khangkhan
JRadioButton radioName =
    new JRadioButton(text, icon,




                                                Chapter 10 GUI & Event Handling
         boolValue);
radioName ˈ            F
              JRadioButton
text      ˈ F      F         F  RadioButton
icon       ˈ     F         F    RadioButton
boolValue ˈ          F
               F         ˈ true               20
GUI: RADIOBUTTON




                         Mr.Warawut
                          Khangkhan
public 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
            F
GUI: LIST
            List ˈ

                           F
GUI: LIST




                                         Mr.Warawut
                                          Khangkhan
JList listName = new JList( );
     or




                                           Chapter 10 GUI & Event Handling
JList listName = new JList(dataModel);
     or
JList listName = new JList(items);
listName ˈ         F            JList
dataModel ˈ              F     F1
                   F 1
items     ˈ F                Object
                                         23
                Vector
Example: Ch10_06

GUI: SCROLLPANE




                                             Mr.Warawut
                                              Khangkhan
 ScrollPane ˈ           F   F
 Scroll bar F          JScrollPane




                                               Chapter 10 GUI & Event Handling
JScrollPane panelist =
          new JScrollPane(listName);
panelist   ˈ       F
               JScrollPane
listName ˈ       F      List
                                             24
GUI: CHECKBOX




                                               Mr.Warawut
                                                Khangkhan
  CheckBox ˈ               F       F
         F   F                 F




                                                 Chapter 10 GUI & Event Handling
  JCheckBox               ˈ true       false
JCheckBox checkName =
        new JCheckBox(text, icon);
checkName ˈ            F
                  JCheckBox
text          ˈ F    F   F       CheckBox
                                               25
icon      ˈ       F   F        CheckBox
Example: Ch10_07

GUI: COMBOBOX




                                            Mr.Warawut
                                             Khangkhan
 ComboBox ˈ          F
 F      F 1                      F    F




                                              Chapter 10 GUI & Event Handling
   1     F       F
 JComboBox
JComboBox comboName =
        new JComboBox(items);
comboName    ˈ       F
            JComboBox
                                            26
items          ˈ   F       Object
            Vector
Mr.Warawut
                     Chapter 10 GUI & Event Handling
         Khangkhan
                                                       27
            F
                     F
            F
            FF F
               F
             F
GUI: MENU


                          F
                     F
            Menu ˈ

                          F
                          F
F MENU




                                   Mr.Warawut
                                    Khangkhan
1. F       F    JMenuBar
JMenuBar menubar =




                                     Chapter 10 GUI & Event Handling
            new JMenuBar( );
2. F           JMenu
JMenu menuName =
            new JMenu(itemName);
3. F   F        JMenuItem
JMenuItem menuItemName =
                                   28
    new JMenuItem(subItemName);
Example: Ch10_08

               F MENU




                                            Mr.Warawut
                                             Khangkhan
4.     F            F




                                              Chapter 10 GUI & Event Handling
menuName.add(menuItemName);

5.         F    F
menubar.add(menuName);

6.      F F Frame         F
setJMenuBar
frameName.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( );                 31
panel.setLayout(new FlowLayout( ));
Mr.Warawut
                            Chapter 10 GUI & Event Handling
                Khangkhan
                                                                   32
                                                              Example: Ch10_09
FLOWLAYOUT MANAGER
                     F
                            F
                     F
                            F
                            F
                     ˈ
BORDERLAYOUT
MANAGER




                                           Mr.Warawut
                                            Khangkhan
 ˈ             F    F        ˈ 5 F
North, South, East, West




                                             Chapter 10 GUI & Event Handling
Center     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
GRIDBAGLAYOUT
MANAGER




                                    Mr.Warawut
                                     Khangkhan
 ˈ           F    F  ˈ F
          F F GridLayout




                                      Chapter 10 GUI & Event Handling
Manager 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
                                                   37
buttonName.addActionListener(new ButtonListener( ));

More Related Content

Similar to Object-Oriented Programming 10

Session and Cookie
Session and CookieSession and Cookie
Session and CookieWarawut
 
Function C
Function CFunction C
Function CWarawut
 
พื้นฐานการออกแบบโปรแกรม
พื้นฐานการออกแบบโปรแกรมพื้นฐานการออกแบบโปรแกรม
พื้นฐานการออกแบบโปรแกรมWarawut
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8Warawut
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7Warawut
 
9789740333036
97897403330369789740333036
9789740333036CUPress
 

Similar to Object-Oriented Programming 10 (6)

Session and Cookie
Session and CookieSession and Cookie
Session and Cookie
 
Function C
Function CFunction C
Function C
 
พื้นฐานการออกแบบโปรแกรม
พื้นฐานการออกแบบโปรแกรมพื้นฐานการออกแบบโปรแกรม
พื้นฐานการออกแบบโปรแกรม
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
9789740333036
97897403330369789740333036
9789740333036
 

More from Warawut

Database design
Database designDatabase design
Database designWarawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6Warawut
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6Warawut
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5Warawut
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3Warawut
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1Warawut
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MISWarawut
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3Warawut
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2Warawut
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1Warawut
 
Upload File
Upload FileUpload File
Upload FileWarawut
 
Form Validation
Form ValidationForm Validation
Form ValidationWarawut
 
Tips & Track
Tips & TrackTips & Track
Tips & TrackWarawut
 
Edit & Delete Data
Edit & Delete DataEdit & Delete Data
Edit & Delete DataWarawut
 
Search Data
Search DataSearch Data
Search DataWarawut
 
Retrieve Data
Retrieve DataRetrieve Data
Retrieve DataWarawut
 
Additional Information
Additional InformationAdditional Information
Additional InformationWarawut
 
Connect MySQL
Connect MySQLConnect MySQL
Connect MySQLWarawut
 

More from Warawut (20)

Database design
Database designDatabase design
Database design
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 
Upload File
Upload FileUpload File
Upload File
 
Login
LoginLogin
Login
 
Form Validation
Form ValidationForm Validation
Form Validation
 
Tips & Track
Tips & TrackTips & Track
Tips & Track
 
Edit & Delete Data
Edit & Delete DataEdit & Delete Data
Edit & Delete Data
 
Search Data
Search DataSearch Data
Search Data
 
Retrieve Data
Retrieve DataRetrieve Data
Retrieve Data
 
Additional Information
Additional InformationAdditional Information
Additional Information
 
Connect MySQL
Connect MySQLConnect MySQL
Connect MySQL
 

Recently uploaded

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 

Recently uploaded (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 

Object-Oriented Programming 10

  • 1. CHAPTER 10 GUI & EVENT HANDLING Mr.Warawut Khangkhan e-Mail: awarawut@hotmail.com Social Media: www.facebook.com/AjWarawut
  • 2. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling GUI 2
  • 3. GUI Mr.Warawut Khangkhan F F F F F ʽ F Graphic User Interface Chapter 10 GUI & Event Handling (GUI) F java.awt javax.swing 3
  • 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. GUI COMPONENT Mr.Warawut Khangkhan F GUI F3 F F Chapter 10 GUI & Event Handling Container ˈ F F ˈ Abstract Class F F2 Top Level F F ˈ F Frame Dialog Non-Top Level F F F ˈ F Panel Scroll Pane 5
  • 6. GUI COMPONENT Mr.Warawut Khangkhan F GUI F3 F F Chapter 10 GUI & Event Handling Simple Component Button, Label, RadioButton, List Pane ComboBox ˈ F Text Component F F F TextField ˈ F 6
  • 7. GUI: FRAME Mr.Warawut Khangkhan Frame: F ˈ F Top-Level Chapter 10 GUI & Event Handling Container F JFrame F F Swing Set F ˁ F F F ˈ GUI F F F 1 ˈ F 7
  • 8. GUI: FRAME Mr.Warawut Khangkhan JFrame frameName = new JFrame(title); Chapter 10 GUI & Event Handling frameName ˈ F JFrame title ˈ F F F 8
  • 9. ʽ F ˆ F setDefaultCloseOperation( ) 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. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 10
  • 11. GUI: PANEL Mr.Warawut Khangkhan Panel: F ˈ F Top-Level Chapter 10 GUI & Event Handling Container F JPanel ˈ F F Container F Frame ˈ F 11
  • 12. GUI: PANEL Mr.Warawut Khangkhan JPanel pName = new JPanel( ); or Chapter 10 GUI & Event Handling JPanel pName = new JPanel(manager); pName ˈ F JPanel manager ˈ LayoutManager F F Panel Default LayoutManger ˈ Flow Layout ˈ F F F F F 12
  • 13. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 13
  • 14. GUI: BUTTON Mr.Warawut Khangkhan Button ˈ ˁ F F JButton Chapter 10 GUI & Event Handling JButton buttonName = new JButton(text); or JButton buttonName = new Jbutton(text, icon); buttonName ˈ F JButton text ˈ F F F ˁ 14 icon ˈ F F ˁ
  • 15. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 15
  • 16. Example: Ch10_04 GUI: LABEL Mr.Warawut Khangkhan Label ˈ F F F ˈ F F JLabel Chapter 10 GUI & Event Handling JLabel lname = new Jlabel(text, icon, Alignment); lName ˈ F JLabel text ˈ F F F Label icon ˈ F F Label Alignment ˈ F Label - SwingConstans.LEFT F 16 - SwingConstants.CENTER - SwingConstants.RIGHT
  • 17. GUI: TEXTFIELD Mr.Warawut Khangkhan TextField ˈ F F F F F JTextField Chapter 10 GUI & Event Handling JTextField textName = new JTextField(text, Length); textName ˈ F JTextField text ˈ F F F TextField Length ˈ TextField 17
  • 18. Example: Ch10_05 GUI: PASSWORDFIELD Mr.Warawut Khangkhan PasswordField ˈ F F F F F F Chapter 10 GUI & Event Handling JPasswordField JPasswordField pw = new JPasswordField(text, Length); textName ˈ F JPasswordField text ˈ F F F PasswordField 18 Length ˈ F
  • 19. GUI: RADIOBUTTON Mr.Warawut Khangkhan RadioButton ˈ F F F F Chapter 10 GUI & Event Handling JRadioButton F ButtonGroup F F F F F 19
  • 20. GUI: RADIOBUTTON Mr.Warawut Khangkhan JRadioButton radioName = new JRadioButton(text, icon, Chapter 10 GUI & Event Handling boolValue); radioName ˈ F JRadioButton text ˈ F F F RadioButton icon ˈ F F RadioButton boolValue ˈ F F ˈ true 20
  • 21. GUI: RADIOBUTTON Mr.Warawut Khangkhan public ButtonGroup( ); Chapter 10 GUI & Event Handling add( ) remove( ) ButtonGroup 21
  • 22. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 22 List F F F F F F F JList JScrollPane F GUI: LIST List ˈ F
  • 23. GUI: LIST Mr.Warawut Khangkhan JList listName = new JList( ); or Chapter 10 GUI & Event Handling JList listName = new JList(dataModel); or JList listName = new JList(items); listName ˈ F JList dataModel ˈ F F1 F 1 items ˈ F Object 23 Vector
  • 24. Example: Ch10_06 GUI: SCROLLPANE Mr.Warawut Khangkhan ScrollPane ˈ F F Scroll bar F JScrollPane Chapter 10 GUI & Event Handling JScrollPane panelist = new JScrollPane(listName); panelist ˈ F JScrollPane listName ˈ F List 24
  • 25. GUI: CHECKBOX Mr.Warawut Khangkhan CheckBox ˈ F F F F F Chapter 10 GUI & Event Handling JCheckBox ˈ true false JCheckBox checkName = new JCheckBox(text, icon); checkName ˈ F JCheckBox text ˈ F F F CheckBox 25 icon ˈ F F CheckBox
  • 26. Example: Ch10_07 GUI: COMBOBOX Mr.Warawut Khangkhan ComboBox ˈ F F F 1 F F Chapter 10 GUI & Event Handling 1 F F JComboBox JComboBox comboName = new JComboBox(items); comboName ˈ F JComboBox 26 items ˈ F Object Vector
  • 27. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 27 F F F FF F F F GUI: MENU F F Menu ˈ F F
  • 28. F MENU Mr.Warawut Khangkhan 1. F F JMenuBar JMenuBar menubar = Chapter 10 GUI & Event Handling new JMenuBar( ); 2. F JMenu JMenu menuName = new JMenu(itemName); 3. F F JMenuItem JMenuItem menuItemName = 28 new JMenuItem(subItemName);
  • 29. Example: Ch10_08 F MENU Mr.Warawut Khangkhan 4. F F Chapter 10 GUI & Event Handling menuName.add(menuItemName); 5. F F menubar.add(menuName); 6. F F Frame F setJMenuBar frameName.setJMenuBar(menubar); 29
  • 30. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling Chapter 10 GUI & Event Handling LAYOUT MANAGER 30
  • 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( ); 31 panel.setLayout(new FlowLayout( ));
  • 32. Mr.Warawut Chapter 10 GUI & Event Handling Khangkhan 32 Example: Ch10_09 FLOWLAYOUT MANAGER F F F F F ˈ
  • 33. BORDERLAYOUT MANAGER Mr.Warawut Khangkhan ˈ F F ˈ 5 F North, South, East, West Chapter 10 GUI & Event Handling Center F F F1 F F F F F 1 F F F ˈ 5 F F Example: Ch10_10 33
  • 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. GRIDBAGLAYOUT MANAGER Mr.Warawut Khangkhan ˈ F F ˈ F F F GridLayout Chapter 10 GUI & Event Handling Manager F F F F 1 F F F 1 1 F F Example: Ch10_12 35
  • 36. Mr.Warawut Khangkhan Chapter 10 GUI & Event Handling 10 EVENT HANDLING 36
  • 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 37 buttonName.addActionListener(new ButtonListener( ));