Introducing the AWT

Introducing the AWT

Introducing the AWT

Introducing the AWT includes topics on AWT classes, Window fundamentals like Component, Container, Window, Panel, Frame, and working with Frame Windows.

AWT Classes

AWT Classes are contained in java.awt package. It is one of the largest packages of Java. AWT is organized in a top-down hierarchical fashion for easy understanding.

Sample of Classes and their description:

Classes Description
AWTEvent encapsulates the AWT events.
AWTEventMuliticaster dispatches events to multilistener.
BorderLayout contains five layouts: north, south, east, west, and center.
Button creates a push-button control

There are more than given classes of AWT.

For backward compatibility, Java still supports all original Java 1.0 methods.

Window fundamentals:

AWT defines windows according to a class hierarchy that adds functionally and specialty with each level. Panel and Frame are the two most common windows. Much of the functionality of these windows are derived from parent classes. Class hierarchies relating to these classes are fundamental for understanding the concept in depth.

Introducing the AWT

Fig: Hierarchy of AWT

Component: 

Component is an abstract class that enca[sulates all the attributes of a visual component except for menus, all user interface elements that are displayed on the screen, and that interacts with the users are subclasses of the component.

Container:

Container is a subclass of components. It has additional methods that allow other components to be nested within it. Other container objects can be stored inside of the container(since they are themselves instances of components).  This makes for a multileveled containment system. This is responsible for the layout or positioning of any components that it contains.

Panel:

Panel class is a concrete subclass of containers. A panel may be thought as of a recursively nestable, concrete screen component.  It is a superclass for the applet. When you run applet using applet viewer, applet viewer provides title and border. Other methods can be added by using add() method inherited from the container. In simple language, the panel does not have its own title bar, menubar, and border.

setSize(), setLocation(), setBounds() methods can be used inherited by the component.

Frame:

it encapsulates what is thought of as “windows”. It has a title bar, menu bar, borders, and resizing corners. It differs among environments.

Canvas:

It is derived from components. It encapsulates a blank window upon which you can draw.

Working with Frame Windows:

Frame is used to create child windows within an applet, and top-level child windows for stand-alone applications. We have two frame’s constructors:

  • frame() throws HeadlessException
  • frame(String title) throws HeadlessException

HeadlessException is thrown if it is an attempt to create a frame window in an environment that does not support user interaction.

Setting the Windows dimensions:

setSize() method is responsible to set the dimensions of the windows. Synax:

void setSize(int newWidth, int newHeight)

void setSize(Dimension newSize)

Here, Dimension getSize() gives results about the current size of windows through Dimension as an object.

Hiding and showing Window:

setVisible() is a must method to show the window.

Syntax:

void setVisible(boolean visibleFlag)

It will be visible or showable if the method’s argument is true otherwise it will be hidden.

Setting a window’s title:

setTitle() is responsible to change the window’s title or setting the window’s title.

Syntax:

void setTitle(String newTitle)

Closing a Frame window:

When using a frame window, your program must remove that windows frame screen when it is closed by calling setVisible(false). To intercept a window-close event, you must implement the windowClosing() method of windowListener interface. Inside windowClosing() you must remove the window from the screen.

You may also like Marketing.

 

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*