0% found this document useful (0 votes)
2 views

event hadling in java

The document provides an overview of Graphical User Interfaces (GUIs), detailing components such as buttons, labels, and windows that facilitate user interaction. It explains the basic terminologies, including components, containers, and panels, and outlines the main aspects of user interfaces: UI elements, layouts, and behavior. Additionally, it describes specific AWT controls like Label, Button, and Checkbox, including their class declarations, constructors, and methods.

Uploaded by

HOD AN
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

event hadling in java

The document provides an overview of Graphical User Interfaces (GUIs), detailing components such as buttons, labels, and windows that facilitate user interaction. It explains the basic terminologies, including components, containers, and panels, and outlines the main aspects of user interfaces: UI elements, layouts, and behavior. Additionally, it describes specific AWT controls like Label, Button, and Checkbox, including their class declarations, constructors, and methods.

Uploaded by

HOD AN
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Graphical User Interface

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

Component is an object having a graphical representation that can be displayed on the screen
Componen
and that can interact with the user. For examples buttons, checkboxes, list and scrollbars of a
t
graphical user interface.

Container object is a component that can contain other components.Components added to a


container are tracked in a list. The order of the list will define the components' front-to-back
Container
stacking order within the container. If no index is specified when adding a component to a
container, it will be added to the end of the list.

Panel provides space in which an application can attach any other components, including other
Panel
panels.

Window is a rectangular area which is displayed on the screen. In different window we can
execute different program and display different data. Window provide us with multitasking
Window
environment. A window must have either a frame, dialog, or another window defined as its
owner when it's constructed.

A Frame is a top-level window with a title and a border. The size of the frame includes any area
Frame designated for the border. Frame encapsulates window. It and has a title bar, menu bar,
borders, and resizing corners.

Canvas component represents a blank rectangular area of the screen onto which the
Canvas application can draw. Application can also trap input events from the use from that blank area
of Canvas component.

Every user interface considers the following three main aspects:


 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). This part will be covered in Layout
chapter.

 Behavior: These are events which occur when the user interacts with UI elements. This part
will be covered in Event Handling chapter.

Every AWT controls inherits properties from Component class.

Sr.
Control & Description
No.

Component
1 A Component is an abstract super class for GUI controls and it represents an object with graphical
representation.

AWT UI Elements:

Following is the list of commonly used controls while designed GUI using AWT.

Sr.
Control & Description
No.

Label
1
A Label object is a component for placing text in a container.

2 Button
This class creates a labeled button.

Check Box
3
A check box is a graphical component that can be in either an on (true) or off (false) state.

Check Box Group


4
The CheckboxGroup class is used to group the set of checkbox.

List
5
The List component presents the user with a scrolling list of text items.

Text Field
6
A TextField object is a text component that allows for the editing of a single line of text.

Text Area
7
A TextArea object is a text component that allows for the editing of a multiple lines of text.

Choice
8 A Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the
menu.

Canvas
9 A Canvas control represents a rectangular area where application can draw something or can receive
inputs created by user.

Image
10
An Image control is superclass for all image classes representing graphical images.

Scroll Bar
11 A Scrollbar control represents a scroll bar component in order to enable user to select from range of
values.

Dialog
12 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.

AWT Label Class

Label is a passive control because it does not create any event when accessed by the user. The label
control is an object of Label. A label displays a single line of read-only text. However the text can be
changed by the application programmer but cannot be changed by the end user in any way.

Class declaration

Following is the declaration for java.awt.Label class:

public class Label

extends Component

implements Accessible

Field

Following are the fields for java.awt.Component class:

 static int CENTER -- Indicates that the label should be centered.

 static int LEFT -- Indicates that the label should be left justified.

 static int RIGHT -- Indicates that the label should be right justified

Constructor &
Description

Label()
1
Constructs an empty label.

Label(String text)
2
Constructs a new label with the specified string of text, left justified.

Label(String text, int alignment)


3 Constructs a new label that presents the specified string of text with the specified
alignment.

Class constructors
Constructor &
Description

Label()
1
Constructs an empty label.

Label(String text)
2
Constructs a new label with the specified string of text, left justified.

Label(String text, int alignment)


3 Constructs a new label that presents the specified string of text with the specified
alignment.

Class methods

S.N. Method & Description

void addNotify()
1
Creates the peer for this label.

AccessibleContext getAccessibleContext()
2
Gets the AccessibleContext associated with this Label.

int getAlignment()
3
Gets the current alignment of this label.

String getText()
4
Gets the text of this label.

protected String paramString()


5
Returns a string representing the state of this Label.

void setAlignment(int alignment)


6
Sets the alignment for this label to the specified alignment.

7 void setText(String text)


Sets the text for this label to the specified text.

AWT Button Class

Button is a control component that has a label and generates an event when pressed. When a button
is pressed and released, AWT sends an instance of ActionEvent to the button, by calling processEvent
on the button. The button's processEvent method receives all events for the button; it passes an
action event along by calling its own processActionEvent method. The latter method passes the
action event on to any action listeners that have registered an interest in action events generated by
this button.

Class declaration

Following is the declaration for java.awt.Button class:

public class Button

extends Component

implements Accessible

Class constructors

S.N. Constructor & Description

Button()
1
Constructs a button with an empty string for its label.

Button(String text)
2
Constructs a new button with specified label.

Class methods

S.N. Method & Description

void addActionListener(ActionListener l)
1
Adds the specified action listener to receive action events from this button.

2 void addNotify()
Creates the peer of the button.

AccessibleContext getAccessibleContext()
3
Gets the AccessibleContext associated with this Button.

String getActionCommand()
4
Returns the command name of the action event fired by this button.

ActionListener[] getActionListeners()
5
Returns an array of all the action listeners registered on this button.

String getLabel()
6
Gets the label of this button.

<T extends EventListener> T[] getListeners(Class<T> listenerType)


7
Returns an array of all the objects currently registered as FooListeners upon this Button.

protected String paramString()


8
Returns a string representing the state of this Button.

protected void processActionEvent(ActionEvent e)


9 Processes action events occurring on this button by dispatching them to any registered
ActionListener objects.

protected void processEvent(AWTEvent e)


10
Processes events on this button.

void removeActionListener(ActionListener l)
11
Removes the specified action listener so that it no longer receives action events from this button.

void setActionCommand(String command)


12
Sets the command name for the action event fired by this button.

void setLabel(String label)


13
Sets the button's label to be the specified string.
AWT CheckBox Class

Checkbox control is used to turn an option on(true) or off(false). There is label for each checkbox
representing what the checkbox does.The state of a checkbox can be changed by clicking on it.

Class declaration

Following is the declaration for java.awt.Checkbox class:

public class Checkbox

extends Component

implements ItemSelectable,Accessible

Class constructors

S.N. Constructor & Description

Checkbox()
1
Creates a check box with an empty string for its label.

Checkbox(String label)
2
Creates a check box with the specified label.

Checkbox(String label, boolean state)


3
Creates a check box with the specified label and sets the specified state.

Checkbox(String label, boolean state, CheckboxGroup group)


4 Constructs a Checkbox with the specified label, set to the specified state, and in the specified check
box group.

Checkbox(String label, CheckboxGroup group, boolean state)


5 Creates a check box with the specified label, in the specified check box group, and set to the
specified state.

Class methods

S.N. Method & Description

1 void addItemListener(ItemListener l)
Adds the specified item listener to receive item events from this check box.

void addNotify()
2
Creates the peer of the Checkbox.

AccessibleContext getAccessibleContext()
3
Gets the AccessibleContext associated with this Checkbox.

CheckboxGroup getCheckboxGroup()
4
Determines this check box's group.

ItemListener[] getItemListeners()
5
Returns an array of all the item listeners registered on this checkbox.

String getLabel()
6
Gets the label of this check box.

<T extends EventListener>T[] getListeners(Class<T> listenerType)


7
Returns an array of all the objects currently registered as FooListeners upon this Checkbox.

Object[] getSelectedObjects()
8
Returns an array (length 1) containing the checkbox label or null if the checkbox is not selected.

boolean getState()
9
Determines whether this check box is in the on or off state.

protected String paramString()


10
Returns a string representing the state of this Checkbox.

protected void processEvent(AWTEvent e)


11
Processes events on this check box.

protected void processItemEvent(ItemEvent e)


12 Processes item events occurring on this check box by dispatching them to any registered ItemListener
objects.
void removeItemListener(ItemListener l)
13 Removes the specified item listener so that the item listener no longer receives item events from this
check box.

void setCheckboxGroup(CheckboxGroup g)
14
Sets this check box's group to the specified check box group.

void setLabel(String label)


15
Sets this check box's label to be the string argument.

void setState(boolean state)


16
Sets the state of this check box to the specified state.

You might also like