A user interface (UI) is a crucial component of any digital or physical system that allows users to interact with a device, application, or machine.
It serves as the point of communication between the user and the system, enabling users to give input and receive feedback or output.
User interfaces can take many forms, from software-based graphical interfaces on a computer screen to physical buttons and controls on a machine.
Graphical User Interface (GUI): A GUI is a visual interface that utilizes a screen and keyboard for input, offering a tactile user experience.
Menu-Driven Interface: This UI relies on a menu of options for navigation, making it user-friendly and straightforward. For instance, ATMs employ menu-driven interfaces for ease of use.
Form-Based Interface: Form-based UIs present users with a limited set of choices for entering data into a program or application, such as a device's settings menu.
Touch User Interface: Touch UIs are based on haptic or tactile input and are commonly found in smartphones, tablets, and other touch screen devices.
Voice User Interface: This UI type involves using auditory commands for communication between humans and machines. Examples include GPS systems, speech-to-text devices, and virtual assistants.
AWT (Abstract Window Toolkit) is a set of Java classes used for creating user interfaces in Java programs.
AWT provides a collection of components and containers that can be used to create UIs for desktop applications.
It is a platform dependent API that creates a graphical user interface (GUI) for Java programs.
A good graphical application can be developed through AWT. AWT is a GUI library, which provides packages and classes to add graphical components (Buttons, Text boxes, Check boxes) to the graphical application. AWT library can be used with any java program. For that you have to import java.awt.* package
यह एक platform dependent API है जो कक जावा programs के किए ग्राकिकि यूजर इंटरफ़े स (GUI create करता है
AWT के द्वारा अच्छी graphical application develop की जा सकती है। AWT एक GUI library होती है, जो graphical application में graphical components (Buttons, Text box, Check box) add करने के किए packages और classes provide करती है।AWT library को ककसी भी java program के साथ यूज़ ककया जा सकता है। उसके किए आपको java.awt.* package को import करना पड़ता है।
Java AWT is an API to develop GUI or Window – based applications in java.
Abstract Window Toolkit
1995
Heavy – Weight component because its components are using the resources of OS and components are platform dependent.
Some features are missing like Radio button etc.
Less Control
Import java.awt package.
There are mainly 2 types of classes of the AWT library.
The AWT library is made up of these two types of classes
Container Class
Component Class
Container is a window. In which you add components. This is the main window of your application, just like your browser window. It serves as the base for the window component. In this window you add components (buttons, text boxes, check boxes etc.). You can also add another container to a container. There are 4 types of container classes in AWT library, you can use any one and add components to it. Most of the frame class is used. These four container classes are being given below.
Types of Container Classes
•Frame: a top-level window that can contain other components
•Panel: a container that can be used to group components together
•Dialog: a window used to display a message or prompt for user input
•Window: A top-level container that represents a window with a title bar and optional menu bar.
Some method of container
1. add(Component comp): Adds the specified component to the container.
2. remove(Component comp): Removes the specified component from the container.
3. setLayout(LayoutManager mgr): Sets the layout manager for the container.
4. getComponents(): Returns an array of all the components in the container.
5. getPreferredSize(): Returns the preferred size of the container.
6. setPreferredSize(Dimension preferredSize): Sets the preferred size of the container.
7. validate(): Validates the container and all its subcomponents.
8. paint(Graphics g): Paints the container and all its subcomponents.
9. setBackground(Color color): Sets the background color of the container.
10. setEnabled(boolean enabled): Enables or disables the container and all its subcomponents
Frame Class
It is subclass of Window.
The Frame is the container that contain title bar and can have menu bars, borders, and resizing corners.
It can have other components like button, textfield, etc
There are two ways to create a Frame :
By instantiating Frame Class
By extending Frame class
Program using Frames – Type 1
import java.awt.*;
class FirstFrame {
FirstFrame() {
Frame f = new Frame();
Button b = new Button("click me");
b.setBounds(30, 50, 80, 30);
f.add(b);
f.setSize(300, 300);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[]) {
FirstFrame f = new FirstFrame();
}
}
Output
Program using Frames – Type 2
import java.awt.*;
class First extends Frame {
First() {
Button b = new Button("click me");
b.setBounds(30, 100, 80, 30);
add(b);
setSize(300, 300);
setLayout(null);
setVisible(true);
}
public static void main(String args[]) {
First f = new First();
}
}
Output
Panel Class
The Panel class is a container component in AWT that is used to group other components together. It provides an area where components can be added and arranged according to a layout manager.
A Panel is a lightweight container and is commonly used to organize user interface components in a logical way. It is often used as a container for grouping related components together, such as buttons, labels, and text fields.
Panel panel = new Panel();
Dialog Class
In AWT, the Dialog class represents a top-level window that can be used to display a message or prompt the user for input. It is similar to a Frame but is typically used for shorter and more focused interactions with the user.
Here are some key features of the Dialog class:
• It can be modal or non-modal, meaning that it can either block input to other windows or allow input to other windows.
• It can have a title, a message, and a set of buttons for user interaction.
• It can be customized with components such as text fields, labels, and checkboxes.
• It can be closed programmatically or by the user clicking on one of the buttons or the close button
import java.awt.*;
import java.awt.event.*;
public class DialogBoxExample {
public static void main(String[] args) {
// Create a frame with a title
Frame frame = new Frame("Dialog Box Example");
// Create a button to show the dialog box
Button showButton = new Button("Show Dialog Box");
showButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Create a dialog with a title and set it to modal (blocks input to the parent frame)
Dialog dialog = new Dialog(frame, "Dialog Box Title", true);
// Create a label to display a message in the dialog
Label label = new Label("Message displayed in the dialog box.");
// Add the label to the dialog
dialog.add(label);
// Pack the dialog to size it according to its contents
dialog.pack();
// Make the dialog visible
dialog.setVisible(true);
}
});
// Add the button to the frame's center
frame.add(showButton, BorderLayout.CENTER);
// Pack the frame to size it according to its contents
frame.pack();
// Make the frame visible
frame.setVisible(true);
}
}
Output:
When you run this code, a window will appear with a button labeled "Show Dialog Box." When you click this button, a modal dialog box with the title "Dialog Box Title" and a message "Message displayed in the dialog box" will appear in the center of the window. The dialog box will block input to the parent frame until it's closed.
Window Class
The Window class in Java AWT is a top-level container that represents a window with a title bar and optional menu bar. It provides methods for managing the window's size, location, and visibility, as well as event handling methods for responding to user actions such as window opening, closing, and resizing.
Here is a simple example of creating a Window
import java.awt.*;
public class MyWindow extends Window {
public MyWindow(Frame owner) {
super(owner); setTitle("My Window");
setSize(400, 300);
setLocationRelativeTo(null); // Center the window on the screen
}
public static void main(String[] args) {
Frame frame = new Frame();
MyWindow window = new MyWindow(frame);
window.setVisible(true);
}
}
Output:
When you run this code, a window with the title "My Window" and dimensions 400x300 pixels will appear on the screen. The setLocationRelativeTo(null) call will center the window on the screen. The window is displayed within a Frame named frame.
Please note that the Window class is typically used for creating lightweight, non-decorated windows or pop-up windows. In modern Java GUI development, Swing or JavaFX is often preferred for creating more sophisticated and customizable user interfaces.
Components are controls with which users interact. Such as button, text-field, scroll-bar and text-area etc. Components are not standalone. You cannot use a component without a container. First you create the component and then add it to the container. Only after this the user can use the components. Each component represents a class. To create a component, you simply create an object of that component class. Some common components and their usage are given below.
Types of Components Classes
1. Button - A simple button that can be clicked by the user.
2. Label - A display area for a short text string or an image.
3. TextField - A text input field where the user can enter a single line of text.
4. TextArea - A text input area where the user can enter multiple lines of text.
5. Checkbox - A graphical control element that allows the user to select one or more options from a set.
6. RadioButton - A graphical control element that allows the user to select one option from a set.
7. Choice - A graphical control element that displays a drop-down list of items from which the user can select one.
8. List - A graphical control element that displays a list of items from which the user can select one or more.
9. Scrollbar - A graphical control element that allows the user to select a value from a range of values by scrolling a thumb along a track.
10. Menu - A graphical control element that displays a list of options or commands from which the user can choose.