PS 8
PS 8
Assignment Title: Create simple application of Java AWT in which show an awt component
button by setting its placement and window frame size.
Pre-Requisites: C/C++
Objective: The objective is to impart fundamentals of Java AWT (Abstract Window Toolkit)
an API to develop Graphical User Interface (GUI) or windows-based applications in Java.
1. Analyze and Work with Frame class, Colour, Fonts and layout managers
2. Design and develop interface components- Labels, Button, Text Components, Check Box,
Check Box Group, Choice, List Box, Panels – Scroll Panel, Menu, Scroll Bar.
Theory:
JAVA AWT
Java AWT (Abstract Window Toolkit) is an API to develop Graphical User Interface (GUI)
or windows-based applications in Java.
Java AWT components are platform-dependent i.e. components are displayed according to
the view of operating system. AWT is heavy weight i.e. its components are using the
resources of underlying operating system (OS).
The java.awt package provides classes for AWT API such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
The AWT tutorial will help the user to understand Java GUI programming in simple and easy
steps.Java Operator Precedence
Java AWT calls the native platform calls the native platform (operating systems) subroutine
for creating API components like TextField, ChechBox, button, etc.
For example, an AWT GUI with components like TextField, label and button will have
different look and feel for the different platforms like Windows, MAC OS, and Unix. The
reason for this is the platforms have different view for their native components and AWT
directly calls the native subroutine that creates those components.
In simple words, an AWT application will look like a windows application in Windows OS
whereas it will look like a Mac application in the MAC OS.
Window
Panel
Frame
Dialog
WINDOW
The window is the container that have no borders and menu bars. You must use frame, dialog
or another window for creating a window. We need to create an instance of Window class to
create this container.
PANEL
The Panel is the container that doesn't contain title bar, border or menu bar. It is generic
container for holding the components. It can have other components like button, text field etc.
An instance of Panel class creates a container, in which we can add components.
FRAME
The Frame is the container that contain title bar and border and can have menu bars. It can
have other components like button, text field, scrollbar etc. Frame is most widely used
container while developing an AWT application.
Conclusion:
Thus we have created simple application of Java AWT in which we have shown an awt
component button by setting its placement and window frame size..
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
Button submitButton ;
public awt_controls()
setTitle("Student Details");
setSize(500, 500);
nameLabel.setBounds(50,100,100,20);
nameField.setBounds(150,100,100,20);
rollnoLabel.setBounds(50,150,100,20);
rollnoField.setBounds(150,150,100,20);
classLabel.setBounds(50,200,100,20);
classField.setBounds(150,200,100,20);
deptLabel.setBounds(50,250,100,20);
deptField.setBounds(150,250,100,20);
addLabel.setBounds(50,300,100,20);
addField.setBounds(150,300,100,20);
submitButton.setBounds(150,325,50,20);
add(nameLabel);
add(nameField);
add(rollnoLabel);
add(rollnoField);
add(classLabel);
add(classField);
add(deptLabel);
add(deptField);
add(addLabel);
add(addField);
add(submitButton);
setLayout(null);
setVisible(true);
addWindowListener(new WindowAdapter() {
System.exit(0);
}
});
new awt_controls();
OUTPUT: