JavaGui
JavaGui
Graphical User Interface (GUI) offers user interaction via some graphical components. For
example our underlying Operating System also offers GUI via window,frame,Panel, Button,
Textfield, TextArea, Listbox, Combobox, Label, Checkbox etc. These all are known as
components. Using these components we can create an interactive user interface for an
application.
GUI provides result to end user in response to raised events.GUI is entirely based events. For
example clicking over a button, closing a window, opening a window, typing something in a
textarea etc. These activities are known as events.GUI makes it easier for the end user to use an
application. It also makes them interesting.
Basic Terminologies
Term Description
Panel Panel provides space in which an application can attach any other
components, including other panels.
Frame A Frame is a top-level window with a title and a border. The size of the
frame includes any area designated for the border. Frame
encapsulates window. It and has a title bar, menu bar, borders, and
resizing corners.
Canvas Canvas component represents a blank rectangular area of the screen onto
which the application can draw. Application can also trap input events
from the use from that blank area of Canvas component
UI elements :Thes are the core visual elements the user eventually sees and interacts
with. GWT provides a huge list of widely used and common elements varying from basic
to complex which we will cover in this tutorial.
Layouts: They define how UI elements should be organized on the screen and provide a
final look and feel to the GUI (Graphical User Interface).
Behavior: These are events which occur when the user interacts with UI elements
AWT UI Elements:
Following is the list of commonly used controls while designed GUI using AWT.
Sr. Control & Description
No.
1 Label
2 Button
3 Check Box
5 List
The List component presents the user with a scrolling list of text items.
6 Text Field
A TextField object is a text component that allows for the editing of a single line
of text.
7 Text Area
A TextArea object is a text component that allows for the editing of a multiple
lines of text.
8 Choice
9 Canvas
10 Image
11 Scroll Bar
12 Dialog
A Dialog control represents a top-level window with a title and a border used to
take some form of input from the user.
13 File Dialog
A FileDialog control represents a dialog window from which the user can select a
file.
Event Handling
What is an Event?
Change in the state of an object is known as event i.e. event describes the change in state of
source. Events are generated as result of user interaction with the graphical user interface
components. For example, clicking on a button, moving the mouse, entering a character
through keyboard,selecting an item from list, scrolling the page are the activities that causes an
event to happen.
Types of Event
The events can be broadly classified into two categories:
Foreground Events - Those events which require the direct interaction of user.They are
generated as consequences of a person interacting with the graphical components in
Graphical User Interface. For example, clicking on a button, moving the mouse, entering
a character through keyboard,selecting an item from list, scrolling the page etc.
Background Events - Those events that require the interaction of end user are known as
background events. Operating system interrupts, hardware or software failure, timer
expires, an operation completion are the example of background events.
APPLETS
Applets are GUI based applications. Applets are created by extending a class
called "Applet".The "Applet" class is available in the "java.applet" package.
1. init()
This is the first method to be executed, when the "Applet" is first run. Mostly
used for initialization of variables and objects.
2. start()
This is the second method to be executed after the init(). This constitutes the
main code of your "Applet".
3. stop()
This method is executed when the "Applet" loses focus.
4. destroy()
This method is executed when the "Applet" is totally shut down.
Output