Graphical User Interface (GUI)
Application
Programming Interface (API): The API provides the core functionality of the
Java programming language. It offers a wide array of useful classes ready for
use in your own applications.There are two sets of
Java APIs for graphics programming: AWT (Abstract Windowing Toolkit)
and Swing.
AWT API was introduced in
JDK 1.0. Most of the AWT components have become obsolete and should be replaced
by newer Swing components.
Swing API, a much more
comprehensive set of graphics libraries that enhances the AWT, was introduced
as part of Java Foundation Classes (JFC) after the release of JDK 1.1. JFC
consists of Swing, Java2D, Accessibility, Internationalization, and Pluggable
Look-and-Feel Support APIs. JFC has been integrated into core Java since JDK
1.2.
AWT Packages
AWT is huge! It
consists of 12 packages of 370 classes (Swing is even bigger, with 18 packages
of 737 classes as of JDK 1.8). Fortunately, only 2 packages
- java.awt and java.awt.event - are commonly-used.The java.awt package
contains the core AWT graphics classes:
Ø GUI Component
classes, such as Button, TextField, and Label,
Ø GUI Container
classes, such as Frame and Panel,
Ø Layout managers, such
as FlowLayout, BorderLayout and GridLayout,
Ø Custom graphics
classes, such as Graphics, Color and Font.
Ø The java.awt.event package
supports event handling:
Ø
Event
classes, such
as ActionEvent, MouseEvent, KeyEvent and WindowEvent,
Ø
Event
Listener Interfaces, such as ActionListener, MouseListener, KeyListener and WindowListener,
Ø
Event
Listener Adapter classes, such as MouseAdapter, KeyAdapter,
and WindowAdapter.
AWT provides
a platform-independent and device-independent interface to
develop graphic programs that runs on all platforms, including Windows, Mac OS,
and Unixes.
Containers
and Components
There are two types of GUI
elements:
Ø Component: Components are elementary GUI
entities, such as Button, Label, and TextField.
Ø Container: Containers, such
as Frame and Panel, are used to hold components in a
specific layout (such as FlowLayout or GridLayout). A
container can also hold sub-containers.
In the above figure, there
are three containers: a Frame and two Panels.
A Frame is the top-level container of an AWT program.
A Frame has a title bar (containing an icon, a title, and the
minimize/maximize/close buttons), an optional menu bar and the content display
area. A Panel is a rectangular area used to group related
GUI components in a certain layout. In the above figure, the top-level Frame contains
two Panels. There are five components: a Label (providing
description), a TextField (for users to enter text), and
three Buttons (for user to trigger certain programmed actions).
GUI components are also
called controls (e.g., Microsoft ActiveX
Control), widgets (e.g., Eclipse's Standard Widget Toolkit, Google
Web Toolkit), which allow users to interact with (or control) the application.
Types of
containers
1.Window
The window is the container
that have no borders and menu bars. You must use frame, dialog or another
window for creating a window.
2.Panel
The Panel is the container
that doesn't contain title bar and menu bars. It can have other components like
button, textfield etc.
3.Frame
The Frame is the container
that contain title bar and can have menu bars. It can have other components
like button, textfield etc.
4.Dialog
Dialog class has
border and title. An instance of the Dialog class cannot exist without an
associated instance of the Frame class.
AWT Container Classes
Ø Top-Level
Containers: Frame, Dialog and Applet
Ø Secondary
Containers: Panel and ScrollPane
AWT Component Classes
AWT
provides many ready-made and reusable GUI components in package java.awt.
The frequently-used
are: Button, TextField, Label, Checkbox, CheckboxGroup (radio
buttons), List, and Choice, as illustrated below.
AWT Components
A
component is an object with a graphical representation that can be displayed on
the screen and that can interact with the user. The Component class
is the abstract parent of the nonmenu-related AWT components.Following is the
list of commonly used controls while designed GUI using AWT.
Control & Description
|
Label
A Label object is a component for placing text in a
container.
|
Button
This class creates a labeled button.
|
Checkbox
A check box is a graphical component that can be in
either an on (true) or off (false) state.
|
Radio Button OR Check Box Groups
The CheckboxGroup class is used to group the set of
checkbox.
|
List
The List component presents the user with a scrolling
list of text items.
|
Text Field
A TextField object is a text component that allows for
the editing of a single line of text.
|
Text Area
A TextArea object is a text component that allows for the
editing of a multiple lines of text.
|
Canvas
A Canvas control represents a rectangular area where
application can draw something or can receive inputs created by user.
|
Image
An Image control is superclass for all image classes
representing graphical images.
|
Comments
Post a Comment