Java provides AWT (Abstract Window Toolkit) and Swing for desktop GUI development. Learn the heavyweight vs lightweight distinction and layout management.
| Feature | AWT (Abstract Window Toolkit) | Swing (Java Foundation Classes) |
|---|---|---|
| Component Type | Heavyweight (uses native OS peer components). | Lightweight (written purely in 100% Java). |
| Platform Dependence | Platform dependent (looks like native Windows/Mac OS). | Platform independent (Pluggable Look and Feel - PLAF). |
| Speed & Memory | Faster execution, higher OS resource consumption. | Slightly slower execution, richer component library. |
| Package Name | java.awt.* (e.g., Button, Frame) |
javax.swing.* (e.g., JButton, JFrame) |
Layout managers automatically position and size GUI components inside a Container:
JPanel. Arranges components left-to-right, top-to-bottom.JFrame. Divides container into 5 regions: NORTH, SOUTH, EAST, WEST, and CENTER.To handle a button click in Swing:
Q: What is the default layout manager for a Swing JFrame?
JFrame defaults to BorderLayout, whereas a JPanel defaults to FlowLayout.