Adjustment Listener Event in Advanced Java Programming

Home » Java » Advance Java» Java Event Handling» AdjustmentListener

Adjustment listener is responsible for handling all the events that are generated where and end user moves the scrollbar. The various integer constants used by the adjustment listener method are:

  1. BLOCK_DECREMENT
  2. BLOCK_INCREMENT
  3. TRACK
  4. UNIT_DECREMENT
  5. UNIT_INCREMENT
  6. ADJUSTMENT_VALUE_CHANGED

Adjustment events are sent by scrollbars.


The applet code listed below constructs two scrollbars. The first is an ordinary scrollbar that delegates adjustment events to the applet. When the scrollbar moves, the applet writes a message to the console.

The second scrollbar is a subclass called SelfScrollbar. This subclass handles its own adjustment events. When the SelfScrollbar moves, the scrollbar itself writes a message to the console.




The above code will be stored in the file called AdjustmentListenerTest.java, which on compilation will crate a class file called AdjustmentListenerTest.class. Now compile this file using below commands in the DOS mode:

C:\>jdk1.4\bin>javac AdjustmentListenerTest.java
C:\>jdk1.4\bin>appletviewer AdjustmentListenerTest.java



"Output of AdjustmentListenerTest.java"


"Output of AdjustmentListenerTest.class in DOS mode"
The first scrollbar delegates adjustment events to the applet, so the applet class must implement the AdjustmentListener interface. The second scrollbar handles its own adjustment events by calling EnableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK) and providing a processedAdjustmentEvent() method.


Download Complete Program

  -  



Event Listener


Action ListenerAdjustment ListenerMouse Listener
Mouse Motion ListenerWindow ListenerKey Listener
Focus ListenerITEM ListenerText Listener


No comments:

Post a Comment