日期:2014-05-20  浏览次数:20703 次

大家知道Slider这个组件吗?这个组件能触发鼠标事件吗?
有时郁闷就是不知道这个组件有哪些对应触发事件可以调用。

------解决方案--------------------
别郁闷,先找找文档,property出来的时候大家不也是先看文档的嘛。没有几个是先去扣源码就可以做什么的了


------解决方案--------------------
Java code

static final int FPS_MIN = 0;
static final int FPS_MAX = 30;
static final int FPS_INIT = 15;    //initial frames per second
. . .
JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL,
                                      FPS_MIN, FPS_MAX, FPS_INIT);
framesPerSecond.addChangeListener(this);

//Turn on labels at major tick marks.
framesPerSecond.setMajorTickSpacing(10);
framesPerSecond.setMinorTickSpacing(1);
framesPerSecond.setPaintTicks(true);
framesPerSecond.setPaintLabels(true);

public void stateChanged(ChangeEvent e) {
    JSlider source = (JSlider)e.getSource();
    if (!source.getValueIsAdjusting()) {
        int fps = (int)source.getValue();
        if (fps == 0) {
            if (!frozen) stopAnimation();
        } else {
            delay = 1000 / fps;
            timer.setDelay(delay);
            timer.setInitialDelay(delay * 10);
            if (frozen) startAnimation();
        }
    }
}

------解决方案--------------------
需要addChangeListener
ChangeListener接口中的方法就是
stateChanged