Java Awt Package Intro Ascii
Java Awt Package Intro Ascii
awt Package
The java.awt package in Java, short for Abstract Window Toolkit, provides a set of classes for
creating and
managing graphical user interfaces (GUIs), handling user input, and managing events. It is one of
the
original Java packages and is primarily used for building desktop applications. The package
provides
basic components for building windows, buttons, scrollbars, panels, and more.
1. Containers: These are components that hold and organize other components.
- Frame: A top-level window with a title and border. Typically used as the main window for an
application.
- BorderLayout: Divides the container into five areas (North, South, East, West, Center).
clicks,
- ActionListener, MouseListener, KeyListener: Interfaces that listen for specific types of events
- Graphics: The base class for drawing shapes, text, and images.
6. Utilities:
Here is a simple program using java.awt to create a basic GUI with a button and a text field:
import java.awt.*;
import java.awt.event.*;
button.addActionListener(new ActionListener() {
});
frame.setLayout(new FlowLayout());
frame.add(label);
frame.add(textField);
frame.add(button);
frame.setSize(300, 200);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
frame.dispose();
});
- Label, TextField, and Button: Basic AWT components added to the frame.
- Event Handling: An ActionListener is added to the button to handle click events, printing the text
from
- WindowListener: Allows the window to close properly when the user clicks the close button.
The java.awt package is foundational for building Java desktop applications and serves as a base
for
more advanced libraries, such as Swing, which offers enhanced GUI components.