Professional Documents
Culture Documents
Java.awt
Override any of the standard window methods, such as init(), start(), and paint()
Once you have defined a Frame subclass, you can create an object of that class. But it
will note be initially visible when created, the window is given a default height and
width.
You can set the size of the window explicity by calling the following method
Void setSize(int height, int width);
Void setSize(dimension d);
Frame Methods
- used to set display user defined message on title bar.
setTitle(String)
Event Listener
A Listener is an object that is notified when an event occurs.
For example:
mouseMotionaListner interface define two events:
When mouse is dragged.
When mouse is moved.
For implementing event listener we have to import the following statements:
import java.awt.event.*;
HOW TO USE EVENTS
Components defined in the AWT generate AWTEvents.
Identify which events you wish to listen for (some components generate more
than one type of event)
Our listener class must register with the component to received events
ActionEvent - ActionListener
AdjustmentEvent - AdjustmentListener
ComponentEvent - ComponentListener
ContainerEvent - ContainerListener
FocusEvent - FocusListener
ItemEvent - ItemListener
MouseEvent - MouseListener
KeyEvent - KeyListener
TextEvent - TextListener
WindowEvent - WindowListener
ActionEvent
The ActionEvent is generated when button is clicked or the item of a list is double
clicked.
First declare an event handler class and specify that the class either implements an
ActionListner interface or extends a class that implements an ActionListener
interface.
For example
Public class MyClass implements ActionListener {
//abstract methods of ActionListner interface
}
ActionEvent Listener
Register an instance of the event handler class as a listener on one or more
components.
For example:
someComponent.addActionListner(instanceOfMyClass)
Include code that implements the methods in listener interface.
mouseDragged Method:
executed when mouse is dragged over the listened-to
component..
mouseMoved Method:
execute when mouse is moved over the listened-to
component...
FocusEvent
This class provide two interface methods:
focusGained:
Called just after the listened-to component gets the
focus.
focusLost:
Called just after the listened-to component Loses the
focus.
WindowEvent Listener
This class provide 8 interface methods:
windowOpened:
Called just after the listened-to window has been shown for the first time.
windowClosing:
Called in response to a user request for the listened-to window to be
closed. To actually close the window, the listener should invoke the windowsdispose or
setVisible(false) method.
windowClosed:
Called just after the listened-to window has closed.
windowIconified:
Called just after the listened-to window is iconified.
windowDeiconified:
Called just after the listened-to window is deiconified.
WindowEvent Class
• windowActivated and windowDeactivated:
itemStateChanged:
Called just after a state change in the listened-to component.
All Content Written By Neha Kumari
Thank You….