Home | » | Java | » | Advance Java | » | Java AWT (Abstract Window ToolKit) |
---|
In Today's World the Most important Interface is the Graphical Interface which provides the Facilities for the user to create their Applications which contains all the Graphical elements. So that JAVA provides various GUI Classes and their Methods those are organized in the form of Packages. The Most important Packages are the Java's AWT Packaged Which Contains 63 Classes and 14 Interface which provides various Functions for a user to create his Application.
Contents
There are 63 Classes and 14 interfaces provided by the AWT Packages which Provides facility for a user to create his Application. And AWT contains various Controls those Plays a Vital Role in the Graphical Application For Example Labels, Command Buttons, Text Boxes, Checkboxes and Radio Buttons and Lists etc. So that AWT provides all these Components in the Form of Classes. So For using any class first you have to import AWT Packages and then create the object of that Control which you want.
For creating any type of user component, first create the component and then add it to the panel or applet for adding a component to an applet the add method of container class is used.
Label | Buttons | Check Boxes | Radio Buttons | |
Choice Controls | TextFields | TextAreas | Scrolling Lists | Scrollbars |
A layout refers to arranging and placing the components in a container this is same like arranging the furniture in a house, for this purpose Java has Layout Manager Interface which is used for Placing the Components in the Container like Applet or in the Panel etc. JAVA 's AWT Package Provides various Layouts to arrange the Components and also provide a method which is also called as setLayout, to set the Layout we have to use this Method and name of object of used Layout.
Laying out an interface – A layout manager determines how components will be arranged when they are added to screen or container , A Container may a Frame , Applet , Panel etc
The AWT package includes classes for layout managers.
Flow Layout | Null Layout | Grid Layout |
Border Layout | Card Layout | Gridbag Layout |
Introducing Abstract Window Toolkit
Window Fundamentals
Java Abstract window tool kit package is used for displaying the data within a GUI Environment. Features of AW T Package are as Followings:
- It provides us a set of user interface components including windows buttons text fields scrolling list etc.
- It provides us the way to laying out these above components.
- It provides to create the events upon these components.
The most commonly used interface is the panels those are used by applets and those are derived from frame which creates a standard window. The hierarchy of this Awt is:-
As you see this Figure this Hierarchical view display all the classes and also their Sub Classes. All the Classes are Contained as a Multi-Level inheritance , As You see that Component Class contains a Panel Class which again Contains a Applet Class so that in the AWT Package are Stored in the form of Multi-values inheritance.
Component Class
This is the super class which defines all the methods for developing the methods those are related with the components and the methods those are related with the Actual Position of the Control and this also provides the various methods to Setup the Sized, Colors either this may a Background or a Foreground Color. It includes all the components those are displayed on the screen and it also defines various types of public methods for managing events such as mouse and keyboard window etc. the Various Methods those are Contained in the Component Class are :-
- Void SetSize(int Width, int Height) : this Method is used to Set the Size by taking the height and width of a Control for Example height of Textbox and width of Textbox. With this Method we Can set height and width of any Control.
- Void SetLocation (int x,int y): Used to Set the location on the Applet and this will take the Coordinates in the Form of x and y.
- Void setBounds(int x,int y,int width,int height) : this Method will also set the Acual Loction in the Applet by Specifying the X and y Coordinate and also Specify the Width and Height of the Control.
- Void setForeground(Color c) : this Method is used to set the Font Color or Text Color of a Control.
- Void setBackground(Color c) : This Method is used to set the Background Color of a Control whether this may a Control or any Window Like an Applet,Panel etc.
Container
It is subclass of components which Inherits the various Properties from that Class and it provides to laying out the component , that are contains by using the various layout managers. Means how the Components will be displayed in the applet and in which Manner the Components will be displayed in the window. or Position of the Controls without setting the X and y Axis is determined by the Layout Manager and. The Container Provides very important Methods to add or Remove the Components from the Applet or from any other Window. The various Methods those are Contained in the Container class are :
- Void add (object o) :this Method id used to Add a Control in the Applet of in any Container.
- Void remove(object o) : This is used if a user wants to Remove an Control from a Container For Example if a user wants to Remove the Control from a Applet then he may uses this Method.
- void removeAll() : This Method doesn't take any argument and this will remove all the Controls from the Container.
Panel
It is a subclass of container and it is the super class of Applet. It is a window that does not have a title bar menu bar or border. Generally a Panel is used for displaying Multiple Windows in a Single Window and a Panel may have any Layout. And for Adding any Control in the Panel we have to use the Add Method and there are also some important Methods those are Provided by the Panel Class those are Explained below :-
- Panel() : This is the Name of Class For Using you have to Create the object first.
- Void setLocation : Method is used to set the Location of a control in the Panel.
- Void setSize() : This will takes two Arguments and those Arguments will Specify the Width and Height of the Panel.
- Void setBounds : This Method is used to set the Bounds of an Control in the Panel For Example X and y Axis and Width and Height of a Control.
Window
Window is also a Sub Class of a Container and window class creates a top level window. These are not directly created, for this the subclass of window name frame is used and dialogs are used . This is used for displaying a Sub Windows from a Main Window and the various Methods of Window are as follows:-
- Void Pack() : This Method is used for adjusting the Size of Window according to the number of Controls in the Container or in the Applet or in the other window.
- Void show() : This Method is used for displaying a Window.
- Void dispose() : This Method is used for de-allocate the Memory Space which is Consumed by the Controls of the Window.
Working With Frames
Frame Class is also a Sub Class of Window Class and frame class allows to Create a pop-Menus. And Frame Class Provides a Special Type of Window which has a title bar, menu bar , border. Resizing corners and it is a subclass of window class when we creates A frame object within a applet , will display a warning message that a frame window is created by an applet not by any software. But when a frame window is created by a program other than an applet then a normal window is created. The Various Methods those are Provided by the Frame Class are as follows :-
- Frame() : This is name of Class and used for Creating an object of this Class and this will not display any title on the title bar of Frame.
- Frame(String Title) : This will also create an object of Frame Class and this will also Display a Title on the Title bar of the Window.
- Void setsize() : this is Method of Frame Class which will be Accessed by the object of Frame Class and this will takes two Arguments to set the Size in the Form of width and Height .
- Void show() : This is used for displaying or showing a Frame from a Main Window.
- Void setBackground(Color c) : This is used to set the Background Color of the frame.
- Void setLocation(int x,int y) : This Method will display the frame on the window according to the values of x and y coordinates those are Specified Always Remember that For Displaying a Frame you have to set the Layout and the default Layout of the Frame is Border Layout.
Creating a Frame
An instance of frame can be created using any of the above discussed constructors. You can use the frame objects unique methods as well as its inherited method by specifying the frame object name with the method name. The syntax to invoke a method is:
Frame1.show();
The following program code show how to create a frame window:
The above code shows how to create an empty frame. The java.awt.* package should be included in the java programs to implement the functions of AWT classes in your program. Saved file with Framed1.java and follow below commands:
C:\>jdk1.4\bin>javac Framed1.java
C:\>jdk1.4\bin>java Framed1
Download Complete Program
Setting Frame Properties
Frame class inherits all the methods of its super class. The inherited methods such as setSize() and setVisible() enable you to set the propertied for a frame window. The dfault size of frame 0,0 in terms of width and height. You can set the size of a frame at any time in your program using the setSize() method. The syntax to implement the setSize() method is:
void setSize(int width, int height)
void setSize(Dimension size)
In the above syntax, you can specify the width and height of frame window as arguments in the setSize() methods. In addition, you can also specify the dimension for frame window by passing an object of the Dimension class. size is the object of the Dimension class that has width and height fields, which set the size of frame in terms of pixels. These are the two ways of setting frame window size property. You can use the getSize() method to obtain the current size of the frame. The syntax obtain the current size of the frame window is:
Dimension getSize()
This method returns an object of dimension type. This object has width and height fields that store the current size of the frame window, which is displayed on the screen.
Specifying the frame named followed by the method name sets properties for a frame. The following program code shows how to set the properties of a frame window:
Setting the Properties of a Frame
Saved file with Framed.java and follow below commands:
C:\>jdk1.4\bin>javac Framed.java
C:\>jdk1.4\bin>java Framed
Download Complete Program
Canvas
This is als a Special type of Class which is also derived from a Windows Class and this is not a part of AWT hierarchy class and this is one another type of window which is used for creating a blank Area and this will Creates an Empty Area for doing drawing. It provides us a blank window which can be drawn upon it. And it inherits the Properties from the Paint Method from the Graphics Class which is Located in the Component Class.
Very useful tutorials and very easy to understand.
ReplyDeleteJava Training in Velachery
Nice and Informative Blog.
ReplyDeleteVisit us: Java Online Training
Visit us: Core java training
The post is very useful and informative.
ReplyDeleteHome interior designers in coimbatore
Top architects in coimbatore
amazing post, Python Course In Pune
ReplyDeleteJava AWT Abstract Window Toolkit DomaiNesia GUI toolkit in Java that provides a set of components and tools for building graphical user interfaces in Java applications.
ReplyDelete