명품자바 programming 11장 실습문제
2020. 12. 4. 20:37ㆍProgramming Language/JAVA
3.
4.
5.
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Ex5 extends JFrame {
private JSlider slider = null;
public Ex5() {
super("JSlider Practice Frame");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
slider = new JSlider(JSlider.HORIZONTAL,100,200,130);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setPaintTrack(true);
slider.setMinorTickSpacing(10);
slider.setMajorTickSpacing(50);
JLabel label = new JLabel("130");
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
label.setText(Integer.toString(value));
}
});
label.setBackground(Color.GREEN);
label.setOpaque(true);
c.add(slider);
c.add(label);
setSize(400,200);
setVisible(true);
}
public static void main(String[] args) {
new Ex5();
}
}
반응형
'Programming Language > JAVA' 카테고리의 다른 글
명품자바 programming 13장 실습문제 (0) | 2020.12.08 |
---|---|
명품자바 programming 실습문제 10장 (0) | 2020.12.04 |
명품자바 programming 실습문제 9장 (0) | 2020.12.04 |
\n과 \r (Escape String) (0) | 2020.12.02 |