Awt and Swing
Awt and Swing
What is AWT?
• AWT stands for Abstract Window Toolkit, a Java API that allows developers to
create graphical user interfaces (GUIs) for window-based applications.
• you cannot use AWT (Abstract Window Toolkit) for web applications; it is
specifically designed for creating graphical user interfaces (GUIs) on
desktop applications and is not compatible with web browsers
The package used for Swing
is java.awt
AWT Components
AWT? Components
An AWT component can be considered as an object that can be made visible on a graphical
interface screen and through which interaction can be performed.
a. Window: This is a top-level container and an instance of a window class that does not contain
a border or title.
b. Frame: Frame is a Window class child and comprises the title bar, border and menu bars.
Therefore, the frame provides a resizable canvas and is the most widely used container used for
developing AWT-based applications. Various components such as buttons, text fields, scrollbars
etc., can be accommodated inside the frame container.
2. Button: This is used to create a button on the user interface with a specified label. We can
design code to execute some logic on the click event of a button using listeners.
3. Text Fields: This component of java AWT creates a text box of a single line to enter text data.
AWT Components
5. Canvas: This generally signifies an area that allows you to draw shapes on a graphical user
interface.
AWT Components
6. Choice: This AWT component represents a pop-up menu having multiple choices. The option
which the user selects is displayed on top of the menu.
AWT Components
7. Scroll Bar: This is used for providing horizontal or vertical scrolling feature on the GUI.
8. List: This component can hold a list of text items. This component allows a user to choose
one or more options from all available options in the list.
AWT Components
9. Checkbox: This component is used to create a checkbox of GUI whose state can be either
checked or unchecked.
Checkbox CheckboxGrou
p
Swing Components
The package used for Swing
is javax.swing
9.1 Designing Graphical User Interfaces in Java:
Java LayoutManagers:
1.public static final int X_AXIS: Alignment of the components are horizontal
public BoxLayoutExample1 () {
buttons = new Button [5];
// main method
public static void main(String args[]){
BoxLayoutExample1 b=new BoxLayoutExample1();
}
}
9.1 Designing Graphical User Interfaces in Java:
Design Registration Form