Académique Documents
Professionnel Documents
Culture Documents
AWT
AWT Hierarchy
Container
The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc. The classes that
extends Container class are known as container such as Frame,
Dialog and Panel.
Window
The window is the container that have no borders and menu bars.
You must use frame, dialog or another window for creating a
window.
Panel
The Panel is the container that doesn't contain title bar and menu
bars. It can have other components like button, textfield etc.
Frame
The Frame is the container that contain title bar and can have
menu bars. It can have other components like button, textfield
etc.
11.
12.
13.
14.
15.
importjava.awt.*;
classFirstextendsFrame{
First(){
Buttonb=newButton("clickme");
b.setBounds(30,100,80,30);//settingbuttonposition
add(b);//addingbuttonintoframe
setSize(300,300);//framesize300widthand300height
setLayout(null);//nolayoutmanager
setVisible(true);//nowframewillbevisible,bydefaultits
notvisible
}
publicstaticvoidmain(Stringargs[]){
Firstf=newFirst();
}
}
Output
importjava.awt.*;
classFirst2{
First2(){
Framef=newFrame();
Buttonb=newButton("clickme");
b.setBounds(30,50,80,30);
f.add(b);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
publicstaticvoidmain(Stringargs[]){
First2f=newFirst2();
}}
Formative Assessment
1. Give the abbreviation of AWT?
a.Applet Windowing Toolkit
b.Abstract Windowing Toolkit
c.Absolute Windowing Toolkit
d.None of the above
2. These two ways are used to create a Frame
By creating the object of Frame class (association)
By extending Frame class (inheritance)
a.True
b.False
Formative Assessment
Where are the following four methods
commonly used?
1)
2)
3)
4)
public
public
public
public
void
void
void
void
add(Component c)
setSize(int width,int height)
setLayout(LayoutManager m)
setVisible(boolean)
a.Graphics class
b.Component class
c.Both A & B
d.None of the above
Foreground Event
Background Event
EXAMPLE:
ActionEvent - ActionListener
MouseEvent - MouseListener
ContainerEvent - ContainerListener
ComponentEvent -ComponentListener
Declare an event handler class and specify that the class either
implements an ActionListener interface or extends a class that
implements an ActionListener interface.
For example:
public class MyClass implements ActionListener {
Register an instance of the event handler class as a listener on one
or more components.
For example:
someComponent.addActionListener(instanceOfMyClass);
Include code that implements the methods in listener interface.
For example:
public void actionPerformed(ActionEvent e)
{ ...//code that reacts to the action... }
Summary
AWT
Inheritance
Association
Event Handling
Types of Event
Discussion
Mind Map