ChangeEvent: getSource() : ChangeEvent « javax.swing.event « Java by API






ChangeEvent: getSource()

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class MainClass {

  public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ChangeListener listener = new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        System.out.println("Source: " + e.getSource());
      }
    };

    SpinnerModel model3 = new SpinnerNumberModel();
    JSpinner spinner3 = new JSpinner(model3);
    spinner3.addChangeListener(listener);

    frame.add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);

  }

}
           
       








Related examples in the same category