You are on page 1of 25

GRAPHICAL USER INTERFACE

1.1 Understand Abstract Window Toolkit(AWT) Fundamentals

Mrs. FAIROSE BINTI MOHTAR


Bsc.Information Technology (Information Management)
Universiti Utara Malaysia
COURSE LEARNING OUTCOME

1. Apply knowledge and skills to create a user interfaces for an


interactive java programming. (C3,P3, PLO1, PLO2)
2. Produce an interactive application program using appropriate Java
programming environment. (P4, A3, PLO2, PLO4)
Checklist :

1. Define the use of AWT


2. Explain the AWT Hierarchy
3. Use AWT in Java programs
Define the use of AWT
1. The Abstract Window Toolkit (AWT) was the first
version of graphical components for Java.
2. AWT is an API to develop GUI or window-based
applications in java
3. It is a package that provides an integrated set of
classes that enable you to create a graphical user
interface and receive user input from mouse and
keyboard.
GUI >> buttons, labels, textfield.
4. Java is a platform–independent language, the AWT
offers a way to design an interface that will have the
same general appearance and functionality on all
systems it runs on.
5. AWT is heavyweight i.e. its components are using the
resources of OS.
Using the AWT, a user interface consists of three things:
a. components
b. container
c. layout manager
a. Components
i. Anything that can be put onto user interface
including components like windows, buttons,
check boxes, dialog boxes, lists, menus,
scrollbars, and text fields.
ii. The Component class, which implements the
common functionality, is the super class for all
graphical interface
b. Container
i. The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc.
ii. A classic example is the Applet window and others include
panel, dialog boxes, standalone windows.
iii. The classes that extends Container class are known as
container such as Frame, Dialog and Panel.

Dialog box
panel Applet class is used
to run programs
Panel class does not that run in a web
have a title, menu or browser.
border.

Applet window
c. layout manager
i. An object that defines how the components in a
container will be arranged.
ii. You don’t see the Layout Manager in an interface,
but you definitely see the results of its work on
the look and feel of your GUI.
The JavaTM Foundation class (JFC) provides two
frameworks for building GUI based applications
a. Abstract Windowing Toolkit (AWT)
b. Swings
Explain the AWT Hierarchy
Explain the AWT Hierarchy
• The Java AWT (Abstract Window Toolkit) contains the
fundamental classes used for constructing GUIs.
• The abstract Component class is the base class for the AWT.
• Many AWT classes are derived from it. These are the old AWT
components that are no longer in use.
• Some of the AWT classes derived from Component are
Button, Canvas, and Container.
• The JComponent class is derived from Container and is one of
the base classes of Swing.
• The JFrame class is derived from the AWT Frame class. It is
usually the main container for a GUI application.
• The JApplet class is derived from the AWT Applet class and is
used for modern applets.
Explain the AWT Hierarchy
COMPONENT
a) Component is an abstract class.
b) All other classes shown above are non-abstract
(concrete).
c) Component class is superclass of all the non-menu
related user interface classes.
d) It provides support for event handling, drawing of
components etc.
e) Some of the methods of Component class are :
i. void setForeground(Color c)
ii. void setBackground(Color c)
WINDOW
a) Window class represents a top-level window.
b) Both Window and Panel classes do not have title, menus
or borders.
c) The Window class is rarely used directly and its
subclasses Frame and Dialog are more common.
d) The pack method defined in Window class initiates the
layout manager of sub-components of the window.
FRAME
a) The Frame class is a subclass of the Window class. It is
used to create a GUI application window.
b) Frames have title bars, icons and menus.
Useful Methods if Components class
Method Description
public void add(Component c) insert a component on this
component

public void setSize(int width, set the size (width and height) of the
int height) component

public void defines the layout manager for the


setLayout(LayoutManager m) component

public void setVisible(boolean changes the visibility of the


status) component, by default false
Use AWT in Java Programs
AWT Components

• Label:
– Function:
• The object of Label class is a component for placing
text in a container.
• It is used to display a single line of read only text.
• The text can be changed by an application but a
user cannot edit it directly.
AWT Components

• Button:
– Function:
• The button class is used to create a labeled button
that has platform independent implementation.
• The application result in some action when the button
is pushed.
AWT Components

• TextField:
– Function:
• The object of a TextField class is a text component
that allows the editing of a single line text.
• It inherits TextComponent class.
AWT Components

• TextArea:
– Function:
• The object of a TextArea class is a multi line
region that displays text. It allows the editing of
multiple line text.
• It inherits TextComponent class.
AWT Components

• CheckBox:
– Function:
• The Checkbox class is used to create a checkbox.
• It is used to turn an option on (true) or off (false).
• Clicking on a Checkbox changes its state from "on"
to "off" or from "off" to "on".
AWT Components

• ScrollPane:
– Function:
• The object of Scrollbar class is used to add
horizontal and vertical scrollbar.
• Scrollbar is a GUI component allows us to see
invisible number of rows and columns.
Next is Part II

1.2 Create Frame Windows and Menu Bars in Java


program

You might also like