[127] | 1 | package genius.gui.uncertainty;
|
---|
| 2 | import javax.swing.BoxLayout;
|
---|
| 3 | import javax.swing.JFrame;
|
---|
| 4 | import javax.swing.JLabel;
|
---|
| 5 | import javax.swing.SwingUtilities;
|
---|
| 6 | import javax.swing.event.ChangeEvent;
|
---|
| 7 | import javax.swing.event.ChangeListener;
|
---|
| 8 |
|
---|
| 9 | public class SteppingSliderExample
|
---|
| 10 | {
|
---|
| 11 |
|
---|
| 12 | public static void createAndShowGUI()
|
---|
| 13 | {
|
---|
| 14 | JFrame frame = new JFrame("SteppingSlider");
|
---|
| 15 | frame.setSize(500, 120);
|
---|
| 16 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
| 17 | final SteppingSlider steppingSlider = new SteppingSlider(10, 20, 50, 100);
|
---|
| 18 | final String labelPrefix = "Slider value: ";
|
---|
| 19 | final JLabel output = new JLabel(labelPrefix + steppingSlider.getDomainValue());
|
---|
| 20 | steppingSlider.addChangeListener(new ChangeListener()
|
---|
| 21 | {
|
---|
| 22 | @Override
|
---|
| 23 | public void stateChanged(ChangeEvent evt)
|
---|
| 24 | {
|
---|
| 25 | output.setText(labelPrefix + steppingSlider.getDomainValue());
|
---|
| 26 | }
|
---|
| 27 | });
|
---|
| 28 | frame.getContentPane().setLayout(
|
---|
| 29 | new BoxLayout(frame.getContentPane(),
|
---|
| 30 | BoxLayout.Y_AXIS));
|
---|
| 31 | frame.getContentPane().add(steppingSlider);
|
---|
| 32 | frame.getContentPane().add(output);
|
---|
| 33 | frame.setVisible(true);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public static void main(String[] args) throws Exception
|
---|
| 37 | {
|
---|
| 38 | SwingUtilities.invokeLater(new Runnable()
|
---|
| 39 | {
|
---|
| 40 | public void run()
|
---|
| 41 | {
|
---|
| 42 | createAndShowGUI();
|
---|
| 43 | }
|
---|
| 44 | });
|
---|
| 45 | }
|
---|
[66] | 46 | } |
---|