You are on page 1of 33

Event Handling Summary

Sr. No. Interface Methods

1 ActionListener actionPerformed

2 AdjustmentListener adjustmentValueChanged

3 ItemListener itemStateChanged

4 TextListener textValueChanged
componentMoved
componentHidden
5 ComponentListener
componentResized
componentShown
componentAdded
6 ContainerListener componentRemoved

focusGained
7 FocusListener
focusLost
keyPressed
keyReleased
keyTyped
8 KeyListener

mousePressed
mouseReleased
mouseEntered
9 MouseListener mouseExited
9 MouseListener
mouseClicked

mouseDragged
10 MouseMotionListener
mouseMoved
windowClosing
windowOpened
windowIconified
11 WindowListener windowDeiconified
windowClosed
windowActivated
windowDeactivated
dling Summary
Parameter/Accessors Events Generated By
ActionEvent Button
getActionCommand JComboBox
getModifiers JTextField
Timer
AdjustmentEvent JScrollbar
getAdjustable
getAdjustmentType
getValue
ItemEvent getItem AbstractButton
getItemSelectable JComboBox
getStateChange
TextEvent
ComponentEvent Component
getComponent

containerEvent Container
getChild
getContainer
FocusEvent Component
isTemporary
KeyEvent Component
getKeyChar
getKeyCode
getKeyModifiersText
getKeyText
isActionKey
MouseEvent Component
getClickCount
getX
getY
getPoint
translatePoint
isPopupTrigger
MouseEvent Component

WindowEvent Window
getWindow
Event Source & Listener
Interface Events Source
Button
JComboBox
ActionListener
JTextField
Timer
JScrollbar
AdjustmentListener

AbstractButton
ItemListener JComboBox

Component
ComponentListener

Container
ContainerListener

Component
FocusListener
Component

KeyListener

Component

MouseListener
MouseListener

Component
MouseMotionListener
Window

WindowListener
Sr. No. Class Description
AWTEvent Encapsulates AWT events.
1

AWTEventMulticaster Dispatches events to multiple listeners.


2
BorderLayout The border layout manager. Border layouts use five components: North,
3 South, East, West, and Center.
4 Button Creates a push button control.
5 Canvas A blank, semantics-free window.
CardLayout The card layout manager. Card layouts emulate index cards. Only the one on
6 top is showing.
7 Checkbox Creates a check box control.
8 CheckboxGroup Creates a group of check box controls.
9 CheckboxMenuItem Creates an on/off menu item.
10 Choice Creates a pop-up list.
11 Color Manages colors in a portable, platform-independent fashion.
12 Component An abstract superclass for various AWT components.
13 Container A subclass of Component that can hold other components.
14 Cursor Encapsulates a bitmapped cursor.
15 Dialog Creates a dialog window.
Dimension Specifies the dimensions of an object. The width is stored in width, and the
16 height is stored in height.
17 Event Encapsulates events.
18 EventQueue Queues events.
19 FileDialog Creates a window from which a file can be selected.
FlowLayout The flow layout manager. Flow layout positions components left to right, top
20 to bottom.
Font Encapsulates a type font.
21
FontMetrics Encapsulates various information related to a font. This information helps
22 you display text in a window.
Frame Creates a standard window that has a title bar, resize corners, and a menu
23 bar.
Graphics Encapsulates the graphics context. This context is used by the various
24 output methods to display output in a window.
25 GraphicsDevice Describes a graphics device such as a screen or printer.
GraphicsEnvironment Describes the collection of available Font and GraphicsDevice objects.
26

27 GridBagConstraints Defines various constraints relating to the GridBagLayout class.


Sr. No. Class Description
GridBagLayout The grid bag layout manager. Grid bag layout displays components subject
28 to the constraints specified by GridBagConstraints.
GridLayout The grid layout manager. Grid layout displays components in a two-
29 dimensional grid.
Image Encapsulates graphical images.
30

31 Insets Encapsulates the borders of a container.


32 Label Creates a label that displays a string.
List Creates a list from which the user can choose. Similar to the standard
33 Windows list box.
34 MediaTracker Manages media objects.
35 Menu Creates a pull-down menu.
36 MenuBar Creates a menu bar.
37 MenuComponent An abstract class implemented by various menu classes.
38 MenuItem Creates a menu item.
39 MenuShortcut Encapsulates a keyboard shortcut for a menu item.
40 Panel The simplest concrete subclass of Container.
41 Point Encapsulates a Cartesian coordinate pair, stored in x and y.
42 Polygon Encapsulates a polygon.
PopupMenu Encapsulates a pop-up menu.
43

44 PrintJob An abstract class that represents a print job.


45 Rectangle Encapsulates a rectangle.
46 Robot Supports automated testing of AWT-based applications.
Scrollbar Creates a scroll bar control.
47
ScrollPane A container that provides horizontal and/or vertical scroll bars for another
48 component.
SystemColor Contains the colors of GUI widgets such as windows, scroll bars, text, and
49 others.
TextArea Creates a multiline edit control.
50
TextComponent A superclass for TextArea and TextField.
51

52 TextField Creates a single-line edit control.


Toolkit Abstract class implemented by the AWT.
53

54 Window Creates a window with no frame, no menu bar, and no title.


Labels

Button

Check Boxes

CheckboxGroup

Choice

Lists
Scroll Bars

TextField

TextArea
Label( )

Label(String str)

Label(String str, int how)

Button(String caption)

Checkbox( )
Checkbox(String str)
Checkbox(String str, boolean on)
Checkbox(String str, boolean on, CheckboxGroup cbGroup)
Checkbox(String str, CheckboxGroup cbGroup, boolean on)

Choice( )

List( )
List(int numRows)
List(int numRows, boolean multipleSelect)
Scrollbar( )
Scrollbar(int style)
Scrollbar(int style, int initialValue, int thumbSize, int min, int max)

TextField( )
TextField(int numChars)
TextField(String str)
TextField(String str, int numChars)

TextArea( )
TextArea(int numLines, int numChars)
TextArea(String str)
TextArea(String str, int numLines, int numChars)
TextArea(String str, int numLines, int numChars, int sBars)
The first version creates a blank label.

The second version creates a label that contains the


string specified by str. This string is left-justified.
The value of how must be one of these three
constants: Label.LEFT, Label.RIGHT, or
Label.CENTER.

The label is obtained by calling the


getActionCommand( ) method on the ActionEvent
object passed to actionPerformed( ).
style is Scrollbar.VERTICAL
Scrollbar.HORIZONTAL
Methods

void setText(String str)

String getText( )
void setAlignment(int how)
int getAlignment( )

boolean getState( )
void setState(boolean on)
String getLabel( )
void setLabel(String str)

Checkbox getSelectedCheckbox( )
void setSelectedCheckbox(Checkbox which)

void add(String name)


String getSelectedItem( )
int getSelectedIndex( )

void add(String name)


void add(String name, int index)
String getSelectedItem( )
int getSelectedIndex( )
void setValues(int initialValue, int thumbSize, int min, int max)
int getValue( )
void setValue(int newValue)
int getMinimum( )
int getMaximum( )
void setUnitIncrement(int newIncr)
void setBlockIncrement(int newIncr)

String getText( )
void setText(String str)
String getSelectedText( )
void select(int startIndex, int endIndex)
boolean isEditable( )
void setEditable(boolean canEdit)
void setEchoChar(char ch)
boolean echoCharIsSet( )
char getEchoChar( )

void append(String str)


void insert(String str, int index)
void replaceRange(String str, int startIndex, int endIndex)
Labels

Button

Check Boxes

CheckboxGroup

Choice

Lists
Scroll Bars

TextField

TextArea
Label( )

Label(String str)

Label(String str, int how)

Button(String caption)

Checkbox( )
Checkbox(String str)
Checkbox(String str, boolean on)
Checkbox(String str, boolean on, CheckboxGroup cbGroup)
Checkbox(String str, CheckboxGroup cbGroup, boolean on)

Choice( )

List( )
List(int numRows)
List(int numRows, boolean multipleSelect)
Scrollbar( )
Scrollbar(int style)
Scrollbar(int style, int initialValue, int thumbSize, int min, int max)

TextField( )
TextField(int numChars)
TextField(String str)
TextField(String str, int numChars)

TextArea( )
TextArea(int numLines, int numChars)
TextArea(String str)
TextArea(String str, int numLines, int numChars)
TextArea(String str, int numLines, int numChars, int sBars)
The first version creates a blank label.

The second version creates a label that contains the


string specified by str. This string is left-justified.
The value of how must be one of these three
constants: Label.LEFT, Label.RIGHT, or
Label.CENTER.

The label is obtained by calling the


getActionCommand( ) method on the ActionEvent
object passed to actionPerformed( ).
style is Scrollbar.VERTICAL
Scrollbar.HORIZONTAL
Methods

void setText(String str)

String getText( )
void setAlignment(int how)
int getAlignment( )

boolean getState( )
void setState(boolean on)
String getLabel( )
void setLabel(String str)

Checkbox getSelectedCheckbox( )
void setSelectedCheckbox(Checkbox which)

void add(String name)


String getSelectedItem( )
int getSelectedIndex( )

void add(String name)


void add(String name, int index)
String getSelectedItem( )
int getSelectedIndex( )
void setValues(int initialValue, int thumbSize, int min, int max)
int getValue( )
void setValue(int newValue)
int getMinimum( )
int getMaximum( )
void setUnitIncrement(int newIncr)
void setBlockIncrement(int newIncr)

String getText( )
void setText(String str)
String getSelectedText( )
void select(int startIndex, int endIndex)
boolean isEditable( )
void setEditable(boolean canEdit)
void setEchoChar(char ch)
boolean echoCharIsSet( )
char getEchoChar( )

void append(String str)


void insert(String str, int index)
void replaceRange(String str, int startIndex, int endIndex)
Layout Manager

FlowLayout

BorderLayout

GridLayout
Methods
setLayout( )

Constructors
FlowLayout( )
FlowLayout(int how)
FlowLayout(int how, int horz, int vert)

BorderLayout( )
BorderLayout(int horz, int vert)

GridLayout( )
GridLayout(int numRows, int numColumns)
GridLayout(int numRows, int numColumns, int horz, int vert)
Layout Managers
Syntax
void setLayout(LayoutManager layoutObj)

Parameter
Valid values for how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
FlowLayout.LEADING
FlowLayout.TRAILING

BorderLayout.SOUTH
BorderLayout.WEST
BorderLayout.NORTH
BorderLayout.EAST
BorderLayout.CENTER
out Managers

SetLayout(LayoutManagerObj);

setLayout(new FlowLayout(FlowLayout.LEFT));

setLayout(new BorderLayout());

setLayout(new GridLayout(n, n));


Examples

void add(Component compObj, Object region)


add(new Button("This is across the top."),BorderLayout.NORTH);
add(new Label("The footer message might go here."),BorderLayout.SOUTH);
add(new Button("Right"), BorderLayout.EAST);
add(new Button("Left"), BorderLayout.WEST);
AWT and Swing Classes

Sr. No. Component Type AWT Swing


1 Panel Panel Jpanel
2 Frame Frame JFrame

Sr. No. Component Type AWT


1 Labels Label
2 Push buttons Button Checkbox
3 Check boxes (RadioButton) Checkbox CheckboxGroup
4 Choice lists Choice
5 List List
6 Scroll bars ScrollBar ScrollPane
7 Text editing TextField TextArea
8 Menu Bar MenuBar
9 Menu Menu
10 Menu Item MenuItem
11 Popup Menu PopupMenu
Swing Classes

Swing
JLabel
JButton JCheckBox
JRadioButton ButtonGroup
JComboBox
JList
JScrollBar
JTextField JTextArea JPasswordField
JMenuBar
JMenu
JMenuItem JCheckBoxMenuItem JRadioButtonMenuItem
JPopupMenu
Sr. No. Listener Interface Adapter Class
1 ComponentListener ComponentAdapter
2 ContainerListener ContainerAdapter
3 FocusListener FocusAdapter
4 KeyListener KeyAdapter
5 MouseListener MouseAdapter
6 MouseMotionListener MouseMotionAdapter
7 WindowListener WindowAdapter
Methods of AdapterClass

addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
showStatus("Mouse Pressed");
}
});

You might also like