unit3_Introduction_toAWT
unit3_Introduction_toAWT
• AWT classes
• Window fundamentals:
– component,
– container,
– panel,
– window,
– frame,
– console
• Working with frame windows:
– setting windows dimensions,
– hiding and showing and closing windows
• Creating a frame window in an applet
AWT Class
• The Java programming language class library
provides a user interface toolkit called the
Abstract Windowing Toolkit, or the AWT
What is a user interface
• The user interface is that part of a program that
interacts with the user of the program.
• User interfaces take many forms.
• These forms range in complexity from simple
command-line interfaces to the point-and-click
graphical user interfaces provided by many
modern applications.
• At the lowest level, the operating system
transmits information from the mouse and
keyboard to the program as input, and provides
pixels for program output.
• The AWT was designed so that programmers
don't have worry about the details of tracking
the mouse or reading the keyboard, nor attend
to the details of writing to the screen.
• The AWT provides a well-designed object-
oriented interface to these low-level services
and resources.
Components and containers
Components
• A graphical user interface is built of graphical elements called components.
• Typical components include such items as buttons, scrollbars, and text fields.
• Components allow the user to interact with the program and provide the user
with visual feedback about the state of the program.
• In the AWT, all user interface components are instances of class Component or
one of its subtypes.
• Spatially, components must fit completely within the container that contains
them.
• This nesting of components (including containers) into containers creates a tree
of elements, starting with the container at the root of the tree and expanding out
to the leaves, which are components such as buttons.
Containers
• Components do not stand alone, but rather are found within containers.
• Containers contain and control the layout of components. Containers are
themselves components, and can thus be placed inside other containers.
• In the AWT, all containers are instances of class Container or one of its
subtypes.
Types of containers
• The AWT provides four container classes. They
are class Window and its two subtypes –
• class Frame and class Dialog -- as well as the
Panel class.
• In addition to the containers provided by the
AWT, the Applet class is a container -- it is a
subtype of the Panel class and can therefore hold
components.
• Brief descriptions of each container class
provided by the AWT are provided below.
• The AWT provides nine basic non-container
component classes from which a user interface
may be constructed. (Of course, new
component classes may be derived from any of
these or from class Component itself.)
• These nine classes are class Button, Canvas,
Checkbox, Choice, Label, List, Scrollbar,
TextArea, and TextField
Window
The setSize( ) method is used to set the dimensions of the window. Its
signature is shown here:
Dimension getSize( )
This method returns the current size of the window contained within
the width and height fields of a Dimension object.
Hiding and Showing a Window
After a frame window has been created, it will
not be visible until you call setVisible( ). Its
signature is shown here:
}
public void stop()
{
f.setVisible(false);
}
public void paint(Graphics g)
{
g.drawString("this is in applet window",50,80);
}