SlideShare a Scribd company logo
AWT
(Abstract Window Toolkit)
BY NEHA KUMARI
INTRODUCTION
Abstract Window Toolkit (AWT) is an API to develop GUI or Window based
applications in Java.
A Graphical User Interface (GUI) is built of graphical elements called
component. AWT provides various components such as buttons, labels, text fields,
checkboxes etc. used for creating GUI elements for Java applications.
Java AWT components are platform dependent that is components are
displayed according to the view of operating system.
The Container class is a subclass of component. Container class used to
display non-container class. AWT provides containers like Panels, Frames and Dialogues
to organize and group components in the application.
In Java GUI can be design using same predefined classes. All these classes
are defined in java.awt package.
java.awt class
Java.awt
Container classes
Panel
Applet
Window
Frame Dialog
Non-Container classes
Label TextField Button Checkbox Choice List Scrollbar
The AWT provides container and non-container component classes.
Container Class
 Window: The Window is a top-level container that represents a graphical
window or dialog box. Window class extends the container class,
which means it can contain other components such as buttons, labels
and text fields.
 Frame: The Frame is the container that contains title bar and border and can
menu bars. It can have other components like button, text field etc.
 Panel: The Panel is the container that doesn’t contain title bar and menu bars,
It is a light weight container that can be used grouping other components
together within a window or a frame. It can have other components like
button, text field etc.
 Dialog: It represents a rectangular area where application can draw something
or can receive inputs created by user.
Note: Before adding the components that make up a user interface, the programmer must create a container.
Creating the Frame
Create a subclass of Frame
Override any of the standard window methods, such as init(), start(), and paint()
Implement the windowClosing() method of the windowlistener interface.
Calling setVisible(false) when the window is closed.
Once you have defined a Frame subclass, you can create an object of that class.
But it will note be initially visible when created, the window is given a default height
and width.
You can set the size of the window explicity by calling the following method
Void setSize(int height, int width);
Void setSize(dimension d);
dimension d = new dimension(400, 400);
Frame Methods
 setTitle(String)
 setBackground(color)
 setForground(color)
 setSize(dimension)
 setVisible(boolean)
 setLayout()
 Add(component)
- used to set display user defined message on title bar.
- used to set background color.
- used to set foreground or text color.
- set the width and height for frame.
- Set the frame is visible or not.
- Used to set any layout to the frame.
- Add component to the frame.
Event Handling
Event :
An event is an Object that describes a
state change in a Source.
Some of the activities that cause event
to be generated are:
• Pressing a Button.
• Entering a character through Key
Board.
• Selecting an item from a list etc.
Event Source :
A source is an object that generates an
event. Some general Event sources
are,
 Buttons
 CheckBox
 List
 Text items
EVENT HANDLING
Here is a general form for adding a listener to an event source :
public void addTypeListner(TypeEvent e)
Here,
type is the name of the event.
e is the reference of the event listener.
Event Listener
A Listener is an object that is notified when an event occurs.
For example:
mouseMotionaListner interface define two events:
When mouse is dragged.
When mouse is moved.
For implementing event listener we have to import the following statements:
import java.awt.event.*;
HOW TO USE EVENTS
 Components defined in the AWT generate AWTEvents.
 Identify which events you wish to listen for (some components generate more
than one type of event)
 Identify the Listener class which Listens for the event
 Once we have identified the Listener interface, implement the Listener
interface.
 Our listener class must register with the component to received events
 Call the addXXXListener method where XXX is the Event type.
AWT EVENT
 ActionEvent - Action has occurred (e.g. Button pressed)
 AdjustmentEvent - “Adjustable” Component changed
 ComponentEvent - Component Changed
 ContainerEvent - Container changed (add or remove)
 FocusEvent - Focus Changed
 ItemEvent - Item selected or deselected
 MouseEvent - Mouse event
 KeyEvent - Keyboard event
 TextEvent - Text changed evets
 WindowEvent - Window related events
The following is a list of events in the java.awt.event package:
LISTNER INERFACE
 ActionEvent - ActionListener
 AdjustmentEvent - AdjustmentListener
 ComponentEvent - ComponentListener
 ContainerEvent - ContainerListener
 FocusEvent - FocusListener
 ItemEvent - ItemListener
 MouseEvent - MouseListener
 KeyEvent - KeyListener
 TextEvent - TextListener
 WindowEvent - WindowListener
The following events have Listeners associated with them:
ActionEvent
The ActionEvent is generated when button is clicked or the item of a list is double
clicked.
To write an Action Listener, follow the steps given below:
First declare an event handler class and specify that the class either implements an
ActionListner interface or extends a class that implements an ActionListener
interface.
For example
Public class MyClass implements ActionListener {
//abstract methods of ActionListner interface
}
ActionEvent Listener
Register an instance of the event handler class as a listener on one or more
components.
For example:
someComponent.addActionListner(instanceOfMyClass)
Include code that implements the methods in listener interface.
Public void actionPerformed(ActionEvent e){
If(e.getSource()==someComponent(){
//code that reacts to the action
}
}
KeyEvent
On entering the character from any source generates the key event. This interface
has 3 methods. These are
Public void keyEvent(keyEvent ae){
//active on typing a code .....
}
Public void keyPressed(KeyEvent ae){
//active on pressing a key…….
}
Public void keyPressed(KeyEvent ae){
//active on pressing a key .....
}
Mouse Event
• This event indicates a mouse action occurred in a component.
• This class has 5 interface method as follows:
Public void mousePressed(MouseEvent e) {…….}
Called just after the user presses a mouse button while the cursor is over the
listened-to component.
Public void mouseReleased(MouseEvent e) {…….}
Called just after the user releases a mouse button after a mouse press over the
listened-to component
Public void mouseClicked(MouseEvent e) {……..}
Called just after the user clicks the listened-to component.
Public void mouseEntered(MouseEvent e) {……}
Called just after the cursor enters the bounds of the listened-to component.
Public void mouseExcited(MouseEvent e) {…….}
Called just after the cursor exits the bounds of the listened-to component.
MouseMotionEvent
• The interface MouseMotionEvent indicates a mouse action occurred in a
component.
• This low level event is generated by a component object when mouse is
dragged or moved.
• This class provides 2 interface methods:
mouseDragged Method:
executed when mouse is dragged over the listened-to component..
mouseMoved Method:
execute when mouse is moved over the listened-to component...
FocusEvent
This class provide two interface methods:
focusGained:
Called just after the listened-to component gets the focus.
focusLost:
Called just after the listened-to component Loses the focus.
WindowEvent Listener
This class provide 8 interface methods:
windowOpened:
Called just after the listened-to window has been shown for the first time.
windowClosing:
Called in response to a user request for the listened-to window to be closed. To
actually close the window, the listener should invoke the windowsdispose or
setVisible(false) method.
windowClosed:
Called just after the listened-to window has closed.
windowIconified:
Called just after the listened-to window is iconified.
windowDeiconified:
Called just after the listened-to window is deiconified.
WindowEvent Class
• windowActivated and windowDeactivated:
Called just after the listened-to window is activated or deactivated,
respectively. These methods are not send to windows that are not frames
or dialogs.
We use windowGainedFocus and windowLostFocus methods to
determine when a window gains or loses the focus.
ItemEvent Class
 This class provide one interface method:
itemStateChanged:
Called just after a state change in the listened-to component.
All Content Written By Neha Kumari

More Related Content

PPT
engineeringdsgtnotesofunitfivesnists.ppt
PPT
Unit 5.133333333333333333333333333333333.ppt
PPT
Chapter 8 event Handling.ppt m m m m m m
PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
PPTX
Event Handling in JAVA
PPT
Unit 6 Java
PPTX
What is Event
PPT
Java eventhandling
engineeringdsgtnotesofunitfivesnists.ppt
Unit 5.133333333333333333333333333333333.ppt
Chapter 8 event Handling.ppt m m m m m m
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Event Handling in JAVA
Unit 6 Java
What is Event
Java eventhandling

Similar to Java Abstract Window Toolkit (AWT) Presentation. 2024 (20)

PDF
Ajp notes-chapter-03
PPTX
tL20 event handling
PPTX
JAVA AWT
PDF
java-programming GUI- Event Handling.pdf
PPTX
javaprogramming framework-ppt frame.pptx
PPTX
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
PPT
Java gui event
PPTX
Creating GUI.pptx Gui graphical user interface
PPTX
JAVA AWT presentation for awt key events.pptx
PPT
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
PPTX
Advance Java Programming(CM5I) Event handling
PPTX
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
PPTX
Event handling
PPT
Basic of Abstract Window Toolkit(AWT) in Java
PPTX
ITE 1122_ Event Handling.pptx
PPT
09events
PDF
Advance java for bscit
PDF
Event Handling in Java as per university
PDF
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
PPT
Events1
Ajp notes-chapter-03
tL20 event handling
JAVA AWT
java-programming GUI- Event Handling.pdf
javaprogramming framework-ppt frame.pptx
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
Java gui event
Creating GUI.pptx Gui graphical user interface
JAVA AWT presentation for awt key events.pptx
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
Advance Java Programming(CM5I) Event handling
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
Event handling
Basic of Abstract Window Toolkit(AWT) in Java
ITE 1122_ Event Handling.pptx
09events
Advance java for bscit
Event Handling in Java as per university
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
Events1
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PPTX
Institutional Correction lecture only . . .
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Presentation on HIE in infants and its manifestations
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
GDM (1) (1).pptx small presentation for students
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
Institutional Correction lecture only . . .
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Presentation on HIE in infants and its manifestations
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Cell Types and Its function , kingdom of life
2.FourierTransform-ShortQuestionswithAnswers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Anesthesia in Laparoscopic Surgery in India
GDM (1) (1).pptx small presentation for students
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
Ad

Java Abstract Window Toolkit (AWT) Presentation. 2024

  • 2. INTRODUCTION Abstract Window Toolkit (AWT) is an API to develop GUI or Window based applications in Java. A Graphical User Interface (GUI) is built of graphical elements called component. AWT provides various components such as buttons, labels, text fields, checkboxes etc. used for creating GUI elements for Java applications. Java AWT components are platform dependent that is components are displayed according to the view of operating system. The Container class is a subclass of component. Container class used to display non-container class. AWT provides containers like Panels, Frames and Dialogues to organize and group components in the application. In Java GUI can be design using same predefined classes. All these classes are defined in java.awt package.
  • 3. java.awt class Java.awt Container classes Panel Applet Window Frame Dialog Non-Container classes Label TextField Button Checkbox Choice List Scrollbar The AWT provides container and non-container component classes.
  • 4. Container Class  Window: The Window is a top-level container that represents a graphical window or dialog box. Window class extends the container class, which means it can contain other components such as buttons, labels and text fields.  Frame: The Frame is the container that contains title bar and border and can menu bars. It can have other components like button, text field etc.  Panel: The Panel is the container that doesn’t contain title bar and menu bars, It is a light weight container that can be used grouping other components together within a window or a frame. It can have other components like button, text field etc.  Dialog: It represents a rectangular area where application can draw something or can receive inputs created by user. Note: Before adding the components that make up a user interface, the programmer must create a container.
  • 5. Creating the Frame Create a subclass of Frame Override any of the standard window methods, such as init(), start(), and paint() Implement the windowClosing() method of the windowlistener interface. Calling setVisible(false) when the window is closed. Once you have defined a Frame subclass, you can create an object of that class. But it will note be initially visible when created, the window is given a default height and width. You can set the size of the window explicity by calling the following method Void setSize(int height, int width); Void setSize(dimension d); dimension d = new dimension(400, 400);
  • 6. Frame Methods  setTitle(String)  setBackground(color)  setForground(color)  setSize(dimension)  setVisible(boolean)  setLayout()  Add(component) - used to set display user defined message on title bar. - used to set background color. - used to set foreground or text color. - set the width and height for frame. - Set the frame is visible or not. - Used to set any layout to the frame. - Add component to the frame.
  • 7. Event Handling Event : An event is an Object that describes a state change in a Source. Some of the activities that cause event to be generated are: • Pressing a Button. • Entering a character through Key Board. • Selecting an item from a list etc. Event Source : A source is an object that generates an event. Some general Event sources are,  Buttons  CheckBox  List  Text items
  • 8. EVENT HANDLING Here is a general form for adding a listener to an event source : public void addTypeListner(TypeEvent e) Here, type is the name of the event. e is the reference of the event listener. Event Listener A Listener is an object that is notified when an event occurs. For example: mouseMotionaListner interface define two events: When mouse is dragged. When mouse is moved. For implementing event listener we have to import the following statements: import java.awt.event.*;
  • 9. HOW TO USE EVENTS  Components defined in the AWT generate AWTEvents.  Identify which events you wish to listen for (some components generate more than one type of event)  Identify the Listener class which Listens for the event  Once we have identified the Listener interface, implement the Listener interface.  Our listener class must register with the component to received events  Call the addXXXListener method where XXX is the Event type.
  • 10. AWT EVENT  ActionEvent - Action has occurred (e.g. Button pressed)  AdjustmentEvent - “Adjustable” Component changed  ComponentEvent - Component Changed  ContainerEvent - Container changed (add or remove)  FocusEvent - Focus Changed  ItemEvent - Item selected or deselected  MouseEvent - Mouse event  KeyEvent - Keyboard event  TextEvent - Text changed evets  WindowEvent - Window related events The following is a list of events in the java.awt.event package:
  • 11. LISTNER INERFACE  ActionEvent - ActionListener  AdjustmentEvent - AdjustmentListener  ComponentEvent - ComponentListener  ContainerEvent - ContainerListener  FocusEvent - FocusListener  ItemEvent - ItemListener  MouseEvent - MouseListener  KeyEvent - KeyListener  TextEvent - TextListener  WindowEvent - WindowListener The following events have Listeners associated with them:
  • 12. ActionEvent The ActionEvent is generated when button is clicked or the item of a list is double clicked. To write an Action Listener, follow the steps given below: First declare an event handler class and specify that the class either implements an ActionListner interface or extends a class that implements an ActionListener interface. For example Public class MyClass implements ActionListener { //abstract methods of ActionListner interface }
  • 13. ActionEvent Listener Register an instance of the event handler class as a listener on one or more components. For example: someComponent.addActionListner(instanceOfMyClass) Include code that implements the methods in listener interface. Public void actionPerformed(ActionEvent e){ If(e.getSource()==someComponent(){ //code that reacts to the action } }
  • 14. KeyEvent On entering the character from any source generates the key event. This interface has 3 methods. These are Public void keyEvent(keyEvent ae){ //active on typing a code ..... } Public void keyPressed(KeyEvent ae){ //active on pressing a key……. } Public void keyPressed(KeyEvent ae){ //active on pressing a key ..... }
  • 15. Mouse Event • This event indicates a mouse action occurred in a component. • This class has 5 interface method as follows: Public void mousePressed(MouseEvent e) {…….} Called just after the user presses a mouse button while the cursor is over the listened-to component. Public void mouseReleased(MouseEvent e) {…….} Called just after the user releases a mouse button after a mouse press over the listened-to component Public void mouseClicked(MouseEvent e) {……..} Called just after the user clicks the listened-to component. Public void mouseEntered(MouseEvent e) {……} Called just after the cursor enters the bounds of the listened-to component. Public void mouseExcited(MouseEvent e) {…….} Called just after the cursor exits the bounds of the listened-to component.
  • 16. MouseMotionEvent • The interface MouseMotionEvent indicates a mouse action occurred in a component. • This low level event is generated by a component object when mouse is dragged or moved. • This class provides 2 interface methods: mouseDragged Method: executed when mouse is dragged over the listened-to component.. mouseMoved Method: execute when mouse is moved over the listened-to component...
  • 17. FocusEvent This class provide two interface methods: focusGained: Called just after the listened-to component gets the focus. focusLost: Called just after the listened-to component Loses the focus.
  • 18. WindowEvent Listener This class provide 8 interface methods: windowOpened: Called just after the listened-to window has been shown for the first time. windowClosing: Called in response to a user request for the listened-to window to be closed. To actually close the window, the listener should invoke the windowsdispose or setVisible(false) method. windowClosed: Called just after the listened-to window has closed. windowIconified: Called just after the listened-to window is iconified. windowDeiconified: Called just after the listened-to window is deiconified.
  • 19. WindowEvent Class • windowActivated and windowDeactivated: Called just after the listened-to window is activated or deactivated, respectively. These methods are not send to windows that are not frames or dialogs. We use windowGainedFocus and windowLostFocus methods to determine when a window gains or loses the focus.
  • 20. ItemEvent Class  This class provide one interface method: itemStateChanged: Called just after a state change in the listened-to component.
  • 21. All Content Written By Neha Kumari