04 02 AWT Controls
04 02 AWT Controls
Toolkit
1
Objectives
Describe Abstract Windowing Toolkit (AWT)
3
2. Abstract Windowing Toolkit
Graphical User Interface (GUI) is used to accept input
through a keyboard or a mouse.
4
3. Hierarchy of classes in
Java
Component
TextComponent
Frame(String Title)
Creates an invisible Frame with given title
7
3.1 Containers – Frame Example
Output
8
3.2 Panel
Used to group a number of components together.
9
3.2 Panel Example
Output
10
3.3 Component
Anything that can be placed on a user interface and can
be made visible or resized.
11
4. Various components
Checkbox
Radio button
Text Area
Button
12
4.1 Label
Generally used to indicate the purpose of an item.
Not user-editable .
Label(String labeltext)
Creates a label with a given text
13
4.2 Textfield
GUI element used to input text.
Textfield(int columns)
Creates a new textfield with given number of columns
Textfield(String s)
Creates a new textfield with the given string
Output
15
4.3 TextArea
Used when text is to be accepted has two or more lines.
Includes a scrollbar.
Output
17
4.4 Button
Part of GUI.
Button(String text)
Creates a new Button with the given String
18
4.4 Button :Example
Output
19
4.5 Checkbox
Used for multi-option user input that the user may select or
deselect by clicking them.
Checkbox(String text)
Creates a checkbox with given string as label
20
4.5 Checkbox: Example
Output
21
4.6 Radiobuttons
Used as option button to specify choices.
22
4.6 Radiobuttons: Example
Output
23
4.7 Lists
Displays a list of choices to the user.
Output
25
Event handling with components
An event is generated whenever a user clicks a mouse,
presses or releases a key.
Steps to be followed –
Associate the class with the appropriate listener interface
Identify all components that generate events
Identify all events to be handled
Implement the methods of the listener and write the event
handling code within the methods
27
Event handling with components ...
Event Class Description Interface