0% found this document useful (0 votes)
8 views2 pages

UNIT I - Basic Syntactic Constructs in Java

The document discusses AWT (Abstract Window Toolkit) in Java, which is used for creating GUI applications and provides a variety of UI components and an event management system. It explains the concept of components, their graphical representation, and lists methods of the Component class, including adding listeners and setting visibility. A sample program is provided to demonstrate the use of the Component class in creating a simple frame.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

UNIT I - Basic Syntactic Constructs in Java

The document discusses AWT (Abstract Window Toolkit) in Java, which is used for creating GUI applications and provides a variety of UI components and an event management system. It explains the concept of components, their graphical representation, and lists methods of the Component class, including adding listeners and setting visibility. A sample program is provided to demonstrate the use of the Component class in creating a simple frame.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit 4 Event Handling using AWT and Swing components

Awt:
1.​ AWT stands for Abstract Window Toolkit and they are used to create GUI applications
in Java.
2.​ The awt provides the following:
a.​ A full set of user interface (UI) widgets and other components, including
windows, menus, buttons, check boxes, text fields, scrollbars, and scrolling
list.
b.​ Support for UI containers, which can contain other embedded containers or UI
widgets.
c.​ An event system for managing system and user events among parts of the
awt.
d.​ Mechanisms for laying Management.
Component:
1.​ A Component is an object having a graphical representation that can be displayed
on the screen and that can interact with the user.
2.​ Component class is declared in java.awt package;
3.​ Examples of components are the Frame, Dialog , Buttons, checkboxes, and
scrollbars of a typical graphical user interface.
4.​ Note: Frame, Panel, Applet ,Dialog are Components as well as containers.
5.​ Methods of Component Class
a.​ void addComponentListener(ComponentListener l) - Adds the specified
component listener to receive component events from this component.
b.​ void add(Component c) - Add a component on another component.
c.​ void setVisible(boolean b) - Sets the visibility of the component. It is by
default false.
d.​ void setLayout(LayoutManager m) - Sets the layout manager for the
component.
6.​ Program to demonstrate Methods of Component class

import java.awt.*;
class MyFrame extends Frame {
MyFrame() {
setSize(600, 600);
setTitle("Draw Frame");
setBackground(Color.RED);
setLocation(100, 100);
}

public static void main(String[] args) {


MyFrame f = new MyFrame();
f.setVisible(true);
Dimension d = f.getSize();
System.out.println("Width=" + d.width + " , Height= " +
d.height);
}
}

You might also like