In this article Introduction to AWT we give the information about AWT (Abstract Window Toolkit) is a platform-dependent GUI (Graphical User Interface) library in Java, which is used to build applications with graphical user interface.
Introduction to AWT:
Introduction to AWT (Abstract Window Toolkit):
AWT (Abstract Window Toolkit) is a platform-dependent GUI (Graphical User Interface) library in Java, which is used to build applications with graphical user interface. It is available in the java.awt package of Java. AWT provides a set of GUI components like various windows, buttons, scroll bars, menus, etc., which can be added to an application.
Features of AWT:
1. Platform Dependent:
AWT is platform-dependent because it uses the native GUI components for each platform. This means that AWT may look different depending on different operating systems such as Windows, Mac or Linux.
2. Collection of GUI components:
AWT provides components such as buttons, labels, textfields, checkboxes, lists, and menus, which are used to build the user interface in an application.
3. Containers and layout managers:
AWT uses containers (such as Frame, Panel, Window, Dialog) and layout managers (such as FlowLayout, BorderLayout, GridLayout) to organize UI components in a proper manner.
4. Event Handling:
AWT provides event handling mechanism, where in various user actions (like button click, mouse movement, keyboard input) can be handled. This event model is available under java.awt.event package.
5. Graphics:
Various graphical operations (like drawing lines, circles, image processing) are available to create custom graphics through AWT.
Use of AWT:
AWT is mostly used in applications that require simple and basic GUI. However, it is a bit outdated and now most of the modern Java development uses Swing or JavaFX as these are more flexible and user-friendly. But understanding of AWT is essential as it is the core of Java GUI development.
Components of AWT:-
AWT (Abstract Window Toolkit) is a Java library used to create GUI (Graphical User Interface) applications.
Following are the main components of AWT:
1. Container:
It is a component that holds other components such as buttons, labels, etc.
Example: Frame, Panel, Window, Dialog.
2. Button:
It is a pressable component that is used to perform some action.
Example: Button b = new Button(“Click Me”);
3. Label
It is used to display text that is displayed in the user interface.
Example: Label l = new Label(“Name:”);
4. TextField:
This is a field to input a single line text.
Example: TextField tf = new TextField();
5. TextArea:
This is a multiline text input field.
Example: TextArea ta = new TextArea();
6. Checkbox:
This is a component that is used for selection or rejection.
Example: Checkbox cb = new Checkbox(“Accept Terms”);
7. Radio Button:
It is used to select a single option from a group.
Example: CheckboxGroup cbg = new CheckboxGroup();
8. List:
It is used to display a list from which one or more items can be selected.
Example: List l = new List();
9. Canvas:
It is a blank area on which custom graphics can be drawn.
Example: Canvas c = new Canvas();
10. Scrollbar:
It is a scrolling component which is used to scroll an area.
Example: Scrollbar sb = new Scrollbar();
// Example
import java.awt.*;
import java.awt.event.*;
public class AWTExample
{
public static void main(String[] args)
{
Frame frame = new Frame(“AWT Example”);
Label label = new Label(“Name:”);
label.setBounds(20, 50, 80, 30);
TextField textField = new TextField();
textField.setBounds(100, 50, 150, 30);
Button button = new Button(“Submit”);
button.setBounds(100, 100, 80, 30);
frame.add(label);
frame.add(textField);
frame.add(button);
frame.setSize(300, 200);
frame.setLayout(null);
frame.setVisible(true);
// Closing the window
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
} });
} }
Some More:
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining