我有几个看起来像这样的滑块:
//Create the slider
JSlider speedSlider = new JSlider(JSlider.VERTICAL, MIN_SPEED, MAX_SPEED, initValue);
speedSlider.addChangeListener(controller);
speedSlider.setMajorTickSpacing(MAJOR_TICK_SPACING);
speedSlider.setPaintTicks(true);
panel.add(speedSlider);
在我的 View.java 类中
有Controller.java
public class Controller implements ControllerInterface {
//...
@Override
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
if (!source.getValueIsAdjusting()) {
int speed = (int)source.getValue();
if (0 == speed) {
// stop
}
else {
model.setSpeedBody(speed);
}
}
}
}
问题是我无法确定它到底是什么滑块事件,该怎么做?(ControllerInterface 扩展 ChangeListener)