SliderTest
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class SliderTest extends JFrame{
SliderTest(){
setTitle("SliderTest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSlider slider=new JSlider(SwingConstants.HORIZONTAL);
slider.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
JSlider slider=(JSlider)e.getSource();
int value=slider.getValue();
System.out.println(value);
}
});
slider.setMajorTickSpacing(20);
slider.setMinorTickSpacing(5);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
//slider.setFocusable(true);
/*slider.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
System.out.println(e.getKeyChar());
}
});*/
getContentPane().add(slider);
pack();
setVisible(true);
}
public static void main(String[]args){
new SliderTest();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น