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

PPTX
JAVA AWT
PPT
Unit 5.133333333333333333333333333333333.ppt
PPT
engineeringdsgtnotesofunitfivesnists.ppt
PPTX
javaprogramming framework-ppt frame.pptx
PPT
Java gui event
PPTX
What is Event
PPTX
GUI components in Java
PPTX
Creating GUI.pptx Gui graphical user interface
JAVA AWT
Unit 5.133333333333333333333333333333333.ppt
engineeringdsgtnotesofunitfivesnists.ppt
javaprogramming framework-ppt frame.pptx
Java gui event
What is Event
GUI components in Java
Creating GUI.pptx Gui graphical user interface

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

PPT
09events
PPTX
Event handling
PDF
AWT (Abstract Window Toolkit) Controls.pdf
PPT
Basic of Abstract Window Toolkit(AWT) in Java
PDF
java-programming GUI- Event Handling.pdf
PDF
Ajp notes-chapter-01
PPT
Unit 6 Java
PPTX
JAVA AWT presentation for awt key events.pptx
PPTX
Event Handling in JAVA
DOCX
Lecture8 oopj
PDF
Unit-3 event handling
PPTX
Event Handling in Java
PPT
event handling new.ppt
PPTX
Androd Listeners
PDF
Ajp notes-chapter-03
PPT
AWT information
PPTX
java Unit4 chapter1 applets
PPTX
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
PDF
Event Handling in Java as per university
PPTX
awt and swing new (Abstract Window Toolkit).pptx
09events
Event handling
AWT (Abstract Window Toolkit) Controls.pdf
Basic of Abstract Window Toolkit(AWT) in Java
java-programming GUI- Event Handling.pdf
Ajp notes-chapter-01
Unit 6 Java
JAVA AWT presentation for awt key events.pptx
Event Handling in JAVA
Lecture8 oopj
Unit-3 event handling
Event Handling in Java
event handling new.ppt
Androd Listeners
Ajp notes-chapter-03
AWT information
java Unit4 chapter1 applets
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
Event Handling in Java as per university
awt and swing new (Abstract Window Toolkit).pptx
Ad

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Complications of Minimal Access Surgery at WLH
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Lesson notes of climatology university.
PDF
Pre independence Education in Inndia.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Classroom Observation Tools for Teachers
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
RMMM.pdf make it easy to upload and study
Renaissance Architecture: A Journey from Faith to Humanism
Complications of Minimal Access Surgery at WLH
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Anesthesia in Laparoscopic Surgery in India
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Lesson notes of climatology university.
Pre independence Education in Inndia.pdf
TR - Agricultural Crops Production NC III.pdf
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Microbial diseases, their pathogenesis and prophylaxis
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
Pharmacology of Heart Failure /Pharmacotherapy of CHF
RMMM.pdf make it easy to upload and study
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