Monday, 31 March 2014

AdjustmentListener

  
The listener interface for receiving adjustment events.

AdjustmentListener interface extends the EventListener interface. It contains only one method adjustmentValueChanged.

void adjustmentValueChanged(AdjustmentEvent e)
    Invoked when the value of the adjustable has changed.

import java.awt.event.*;
import javax.swing.*;

class AdjustmentListenerEx extends JPanel{
 static JScrollBar bar = new JScrollBar(SwingConstants.HORIZONTAL, 50, 10, 0, 100);
 
 AdjustmentListenerEx(){
  super();
  /* Registers the Listeners */
  bar.addAdjustmentListener(new AdjustmentListener(){
   public void adjustmentValueChanged(AdjustmentEvent  e){
    JOptionPane.showMessageDialog(null, "Some Adjustment performed");
    System.exit(0);
   }
  });
  add(bar);
 }
 
 public static void main(String args[]){
  JFrame myFrame = new JFrame("Event Handling Example");  
  myFrame.setVisible(true);
  myFrame.setSize(250, 250);
  
  /* Add Button to the frame */
  myFrame.add(new AdjustmentListenerEx());  
 }
}









Prevoius                                                 Next                                                 Home

No comments:

Post a Comment