Overview of AWT
🪟 AWT (Abstract Window Toolkit) in Java
📌 What is AWT?
AWT (Abstract Window Toolkit) is Java’s original platform-independent GUI (Graphical User Interface) toolkit, part of the java.awt package. It allows developers to build graphical applications like forms, buttons, text fields, and windows.
✅ AWT is part of the Java Foundation Classes (JFC).
🧱 AWT Architecture
AWT is built on top of native code using the system's GUI libraries. So when you use AWT, you're actually calling underlying OS GUI components, which makes AWT platform-dependent in look and feel (called heavyweight components).
🔧 Key Features of AWT
-
Provides basic GUI components like
Button,Label,TextField, etc. -
Event-driven programming model.
-
Uses native system components (heavyweight).
-
Supports layout managers for arranging GUI components.
🔢 Core Classes and Interfaces in java.awt
| Component Class | Description |
|---|---|
Frame | Main window |
Button | Push button |
Label | Text label |
TextField | Single-line text input |
TextArea | Multi-line text area |
Checkbox | Checkbox |
CheckboxGroup | Radio buttons |
List | Scrollable list |
Choice | Dropdown menu |
Canvas | For custom drawing |
Panel | Container to hold other components |
Scrollbar | Vertical/horizontal scroll bar |
📚 Layout Managers
AWT uses layout managers to control the positioning of components:
| Layout Manager | Description |
|---|---|
FlowLayout | Left to right, wraps at end |
BorderLayout | North, South, East, West, Center |
GridLayout | Equal-sized grid cells |
CardLayout | One component visible at a time |
GridBagLayout | Flexible grid (complex) |
🎯 Event Handling in AWT
AWT uses Event Delegation Model to handle user interactions.
Key Interfaces:
-
ActionListener– for buttons -
ItemListener– for checkboxes, lists -
KeyListener– for keyboard events -
MouseListener/MouseMotionListener
Example:
⚠️ Limitations of AWT
| Limitation | Description |
|---|---|
| Platform Dependent | Uses native components (inconsistent look) |
| Limited widgets | Lacks rich components (like trees, tables) |
| Heavyweight | Not lightweight like Swing or JavaFX |
✅ When to Use AWT?
-
For simple GUI applications
-
When performance and native look and feel are desired
-
In legacy applications
However, for more modern applications, Swing or JavaFX is recommended.
Comments
Post a Comment