Title: Graphical User Interface GUI
1Graphical User Interface (GUI)
2Graphical User Interface (GUI) Components
- View inputs and outputs simultaneously
- One graphical window
- Input values in any order
- Change input values in window
- Click on buttons to get output
3Java GUI Components
4Graphical User Interface (GUI) Components
- GUI components placed in content pane
- GUI components
- Windows
- Labels
- Text areas
- Buttons
5GUI Components
- Added to content pane of window
- Not added to window itself
- Pixel picture element
6Windows
- Can be created using a Frame object
- The class Frame provides various methods to
control attributes of a window - Measured in pixels of height and width
- Attributes associated with windows
- Title
- Width
- Height
7class Frame
- GUI window instance created as instance of Frame
- Provides various methods to control window
attributes
8Methods Provided by the class Frame
9Methods Provided by the class Frame
10Two Ways to Create a Window
- First way
- Declare object of type Frame
- Instantiate object
- Use various methods to manipulate window
- Second way
- Create class containing application program by
extending definition of class Frame - Utilizes mechanism of inheritance
11Content Pane
- Inner area of GUI window (below title bar, inside
border) - To access content pane
- Declare reference variable of type Container
- Use method getContentPane of class Frame
12Methods Provided by the class Container
13class Label
- Labels objects of particular class type
- class Label used to create labels
- Label attributes
- title
- width
- height
- To create a label
- Instantiate object of type Label
- Modify attributes to control display of labels
14Methods Provided by the class Label
15Methods Provided by the class Label
16class Textile
- Text fields objects belonging to class Textile
- To create text field
- Declare reference variable of type Textile
- Instantiate object
17Methods Provided by the class Textile
18class JButton
- Provided to create buttons in Java
- To create button
- Same technique as creating Label and Textile
19Methods Provided by the class JButton
20Methods Provided by the class JButton
21Handling an Event
- Action event event created when JButton is
clicked - Event listener object which receives message
when JButton is clicked - In Java, you must register the listener
22Handling an Event
- class ActionListener
- Handles action event
- Part of package java.awt.Event
- The class ActionListener is a special type of
class (interface) - Must contain actionPerformed method
23Rectangle Program Sample Run