Examples The following java program is a variation of the previous sample program list. Within this program, the list was made in order to be selected more than one option.
Here is the display program:
Here is an example program:
01 import java.awt .*;
02
03 import java.awt.event .*;
04
05 import javax.swing .*;
06
07 import javax.swing.event .*;
08
09 public class extends JFrame {SimpleSliderDemo
10
11 private JSlider slider;
12
13 private JTextField txtValue;
14
15 public SimpleSliderDemo () {
16
17 super ("JSlider Simple");
18
19 Container container = getContentPane ();
20
21 container.setLayout (new FlowLayout ());
22
23 txtValue = new JTextField (20);
24
25 txtValue.setBackground (Color.WHITE);
26
27 txtValue.setEditable (false);
28
29 slider = new JSlider (SwingConstants.HORIZONTAL, 0,100,50);
30
31 txtValue.setText (String.valueOf (slider.getValue ()));
32
Slider.setMinorTickSpacing 33 (5);
34
Slider.setMajorTickSpacing 35 (20);
36
37 slider.setPaintTicks (true);
38
39 slider.setLabelTable (slider.getLabelTable ());
40
41 slider.setPaintLabels (true);
42
43 slider.addChangeListener (
44
45 new ChangeListener () {
46
47 public void stateChanged (ChangeEvent e) {
48
49 txtValue.setText (String.valueOf (slider.getValue ()));
50
51}
52
53}
54
55);
56
57 container.add (txtValue);
58
59 container.add (slider);
60
61 setSize (280.200);
62
63 setVisible (true);
64
65}
66
67 public static void main (String args []) {
68
69 JFrame.setDefaultLookAndFeelDecorated (true);
70
71 SimpleSliderDemo SimpleSliderDemo test = new ();
72
73 test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
74
75}
76
77}
Langganan:
Posting Komentar (Atom)
0 komentar: