Advanced Java Tutorial


Total available pages count: 55
Subject - Java Technologies

Event Listener in AWT

Basically, the event listener represents the handling of the event using some interfaces. Every method of event listener has an argument as an object which is a subclass of the EventObject class. e.g. mouse event listener will accept the instance of MouseEvent.

EventListener Interface

EventListener is known as the marker interface which every listener interface has to extend. Java.util package has eventListner interface.
 

Declaration of EventListener interface:

public interface EventListener

 

Here are some commonly used event listener

Interface class                    

Declaration

ActionListener

public interface ActionListener extends EventListener

KeyListener

public interface KeyListener extends EventListener 

ItemListener

public interface ItemListener extends EventListener

ComponentListener

public interface ComponentListener extends EventListener

MouseListener

public interface MouseListener extends EventListener

TextListener

public interface TextListener extends EventListener

WindowListener

Public interface WindowListener extends EventListener

AdjustmentListener

public interface AdjustmentListener extends EventListener

ContainerListener

public interface ContainerListener extends EventListener

MouseMotionListener

public interface MouseMotionListener extends EventListener

FocusListener

public interface FocusListener extends EventListener

 

Event Adapter

Event Adapters are abstract classes to receive the various events. The method in adapter classes is empty. These classes exist as a convenience for creating listener objects. 

FocusAdapter

FocusAdapter class is used to receive keyboard focus events.
 

Declaration:

public abstract class FocusAdapter extends Object implements FocusListener

 

KeyAdapter

KeyAdapter class is used to receive keyboard events.
 

Declaration:

public abstract class KeyAdapter extends Object implements KeyListener

 

MouseAdapter

MouseAdapter class is used to receive mouse events.

Declaration: 

Declaration:

public abstract class MouseAdapter extends Object implements mouseListener, mouseWheelListener, MouseMotionListener

 

MouseMotionAdapter

MouseMotionAdapter class is used to receive mouse motion events.
 

 

Declaration:

public abstract class MouseMotionAdapter extends Object implements MouseMotionListener

 

WindowAdapter

Windowadapter class is used to receive window events.

Declaration:

public abstract class WindowAdapter extends Object implements WindowListener, WindowStateListener, WindowFocusListener

 

Container in AWT

The containers are an integral part of GUI components. It provides space where each component can be located. The container is a component & it adds the capability to add the component itself. 

  • Container do add only component itself
  • The child class of containers is called as container e.g. Window, panel & Frame
  • The default layout is present in each container that can be overridden using method setLayout

UI Element in AWT

Panel

The panel class is the simplest container class. the panel provides space in which the application can attach to any other component that includes other panels. The class uses FlowLayout as the Default layout Manager.
 

Declaration:

public class Panel extends Container implements Accessible

 

Panel class inherits method from classes:

  •  java.lang.Object
  • java.awt.Container
  • java.awt.Component

Frame

Frame class is a top-level window with the title & border. The class uses BorderLayout as the default layout manager.
 

Declaration:

public class Frame extends Window implements MenuContainer

 

The Frame class inherits method from classes: 

  1. java.awt.Container
  2. java.awt.Component
  3. java.lang.Object
  4. java.awt.Window

Window

The Window class is a top-level window with no menubar & no border. The class uses BorderLayout is the default layout manager.
 
 

Declaration:

public class Window extends Container implements Accessible

 

The Window class inherits method from classes:

  • java.awt.Container
  • java.awt.Component
  • java.awt.Window
  • java.lang.Object


Comments