List components in Java AWT

Java AWT (Abstract Window Toolkit) is a set of classes and components that facilitate creating a graphical user interface (GUI) in Java. It provides a variety of components that can be used to build user interfaces for desktop applications. In this article, we will explore some of the commonly used components in Java AWT.

1. Frame

A Frame is a top-level window with a title bar and border. It acts as the main container for other components in a Java GUI application. It provides the basic structure for building windows.

Example code:

import java.awt.Frame;

public class MyFrame extends Frame {
    public MyFrame() {
        setTitle("My Frame");
        setSize(400, 300);
        setVisible(true);
    }

    public static void main(String[] args) {
        new MyFrame();
    }
}

2. Panel

A Panel is a container that can hold other components. It is used to group related components together. Panels can be added to frames or other panels to create complex layouts.

Example code:

import java.awt.Frame;
import java.awt.Panel;
import java.awt.Button;

public class MyPanel extends Frame {
    public MyPanel() {
        setTitle("My Panel");
        setSize(400, 300);

        Panel panel = new Panel();
        Button button1 = new Button("Button 1");
        Button button2 = new Button("Button 2");
        panel.add(button1);
        panel.add(button2);

        add(panel);
        setVisible(true);
    }

    public static void main(String[] args) {
        new MyPanel();
    }
}

3. Button

A Button is a clickable component that triggers an action when clicked. It is used to perform actions or submit forms in a GUI application.

Example code:

import java.awt.Frame;
import java.awt.Button;

public class MyButton extends Frame {
    public MyButton() {
        setTitle("My Button");
        setSize(400, 300);

        Button button = new Button("Click Me");
        add(button);

        setVisible(true);
    }

    public static void main(String[] args) {
        new MyButton();
    }
}

Conclusion

These are just a few examples of the components available in Java AWT. There are many other components like Label, TextField, CheckBox, RadioButton, etc., that can be used to create rich graphical user interfaces in Java. By combining these components creatively, you can build powerful and interactive desktop applications.

For more information about Java AWT and its components, you can refer to the official Java documentation.

#java #awt