Registers a change listener on a slider that controls animation speed. The change listener ignores the change events until the user releases the slider. : ChangeListener « Swing Event « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Swing Event » ChangeListener 
15.9.2.Registers a change listener on a slider that controls animation speed. The change listener ignores the change events until the user releases the slider.Previous/Next
Registers a change listener on a slider that controls animation speed. The change listener ignores the change events until the user releases the slider.
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class RegisterChangeListenerToJSlider {

  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL, 1010020);
    framesPerSecond.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        JSlider source = (JSlidere.getSource();
        if (!source.getValueIsAdjusting()) {
          int fps = (intsource.getValue();
          System.out.println(fps);
        }
      }
    });

    frame.add(framesPerSecond,"North");

    frame.setSize(300200);
    frame.setVisible(true);
  }

}
15.9.ChangeListener
15.9.1.Listening to JMenu Events with a ChangeListener: register a ChangeListener with a JMenuListening to JMenu Events with a ChangeListener: register a ChangeListener with a JMenu
15.9.2.Registers a change listener on a slider that controls animation speed. The change listener ignores the change events until the user releases the slider.Registers a change listener on a slider that controls animation speed. The change listener ignores the change events until the user releases the slider.
15.9.3.Uses a change listener on the selection model of a color chooser to learn when the user changes the current color.Uses a change listener on the selection model of a color chooser to learn when the user changes the current color.
15.9.4.Uses a change listener on a date-field spinner to change the color of the text as the spinner's date changes.Uses a change listener on a date-field spinner to change the color of the text as the spinner's date changes.
15.9.5.Tab change listener
15.9.6.Get value of BoundedRangeModel in its change listener
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.