Turn Desktop View Off
You are here:   HomeJava ProgrammingSwingEvent Adapter Class in Java Example
by Dinesh Thakur Category: Swing

The java.awt.event package provides adapter classes for various event-listener types. The event listener interfaces that contain more than one method have a corresponding event adapter class that implements the interface and defines each method in the interface with an empty method body. For example: the adapter class for the WindowListener interface is WindowAdapter.

Events are the primary method for dealing with user, input in the Awt. Each event generated by the AWT equates to one Event object. the handleEvent and action methods we use in most exampleclasses are the standard method of processing AWT events.

Event Useful Interface

Method

Returns

Notes

Event(Object target, int id, Object arg)

 

Use only when constructing events

Event(Object target, long when, int id, int x, int y, int key, int modifiers)

 

 

Event(Object target, long when, int id, int x, int y, int key, int modifiers, Object arg)

 

 

controlDown()

Boolean

Was the Ctrl key down during this event?

controlDown()

Boolean

Was the Ctrl key down during this event?

metaDown()

Boolean

Was the Metakey down during this event?

postEvent(Event evt)

Boolean

Used to post a constructed event

shiftDown()

Boolean

Was the Shift key down during this event?

translate(int dx, int dy)

Void

Translate this event by (dx,dy)

 

import javax.swing.*;

import java.awt.event.*;
import java.awt.*;
class AdapterExample extends JFrame
{
       AdapterExample()
       {
          this.addWindowListener( new WindowAdapter() {
          public void windowClosing(WindowEvent e)
                           {
                              System.exit(0);
                           }
                           });
       }
}
    class AdapterClassJavaExample
{
      public static void main(String [] args)
      {
        AdapterExample frame = new AdapterExample();
        frame.setTitle("Adapter Class Java Example");
        frame.setBounds(100,200,200,200);
        frame.setVisible(true);
      }
}

Event Adapter Class in Java Example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article