java awt
In this post we will read about Java AWT, so let's start.The full name of the awt is the abstract window toolkit.
This is a platform dependent API which creates a graphical user interface (GUI) for Java programs.
AWT contains a large number of classes and methods that allow us to build GUI applications. Such as - textbox, checkbox, button, etc.
To create Java components, we have to use java. awt package.
java awt components, which are platform dependent, i.e. components seem to be different from the operating system. That is, they will look and feel according to the operating system. As if we have created a button that button will look different in windows, different in Mac OS and will look different in UNIX.
AWT which is heavyweight i.e. its components use the resources of the operating system.
Nowadays AWT is used as a no-no because it is platform dependent and heavyweight. Instead, java swing is used. Because by this we can implement the GUI well and this is lightweight.
java AWT hierarchy: -
Java AWT classes are shown below: -components: - All elements such as buttons, text fields, scrollbars, etc. are all components.
container: - Container is a component of AWT that is contained in other components such as buttons, text fields, checkbox, label and it also controls the layout of components.
The container is a subclass of the component class.
Window: - the window is a container with no border and menu bar. To create a window we have to use frame and dialog or another window.
Panel: - The panel does not contain the title bar, menu bar or border. It is used to contain components. Such as - button, text field, etc.
Frame: - the frame is a container that contains the title bar, menu bar or border. It also contains other components such as - buttons, text fields, scrollbars, etc. This container is most commonly used to develop an application in Java AWT.
java awt methods: -
The methods used in java awt are as follows: -
method
description
public void adds (Component c) :- It is used to add an element to the component.
public void setSize (int width, int height) :-It is used to set the size of the component.
public void setLayout (LayoutManager m) :- It is used to define a layout manager for the component.
public void setVisible (boolean status):- It is used to set the visibility of the component.
java awt example: -
This is a simple example of java awt in which the frame class has been inherited: -
import java.awt. *;
class awtexample extends Frame {
awtexample () {
Button b = new button ("click here");
b.setBounds (25,90,75,25); // setting button position
add (b); // adding button in frame
setSize (400,400);
setLayout (null);
setVisible (true);
}
public static void main (String args []) {
awtexample a1 =new awtexample ();
}
}
thanks for sharing.structured cabling companies
ReplyDeleteThank you for sharing this amazing post. Looking forward to reading more.
ReplyDeleteThank you for sharing this amazing post. Looking forward to reading more.
Visit us: Java Online Training Hyderabad
Visit us: Core Java Online Course