Java GUI - AWT and Swing Notes
4.3.1 Creating GUI Application using Frame
- Frame is a top-level window in AWT with title and borders.
- Commonly used to create GUI applications.
- Key methods:
- setSize(width, height): sets frame size
- setTitle("Title"): sets the window title
- setVisible(true): makes the frame visible
4.3.2 Creating Windowed Programs using Applet
- Applet is a Java program that runs in a web browser.
- Extends java.applet.Applet class.
- Lifecycle methods:
- init(): initializes applet
- start(): starts execution
- paint(Graphics g): used for graphics or drawing
- stop(), destroy(): handle cleanup
4.4 AWT Controls
- AWT (Abstract Window Toolkit) provides GUI components.
- Controls like Button, Label, Checkbox, etc. are part of AWT.
- Requires importing java.awt.* package.
4.4.1 class Button
- Used to create a button.
- Constructor: Button(String label)
- Example: Button b = new Button("Click");
4.4.2 class Label
- Displays a non-editable text.
- Constructor: Label(String text)
- Example: Label l = new Label("Name:");
4.4.3 class Checkbox
- Represents a checkbox that can be either checked or unchecked.
- Constructor: Checkbox(String label)
- Example: Checkbox c = new Checkbox("Accept Terms");