奇怪的问题,谁能解释一下。。。。
看下面代码,很简单。就是添加一个滑块,状态改变的时候输出
“滑块状态改变”,但结果是每次状态改变一次都会输出3次结果。
JSlider sliderTest=new JSlider(1,3,3);
sliderTest.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent arg0) {
System.out.println( "滑块状态改变 ");
}
});
fpanel.add(sliderTest);
------解决方案--------------------这样就可以了
JSlider sliderTest=new JSlider(1,3,1);
sliderTest.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println( "滑块状态改变 ");
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
});