001package observer.slider;
002import javax.swing.JSlider;
003import javax.swing.SwingConstants;
004public class Main {
005        public static void main(String[] args) {
006                new M().run();
007        }
008}
009
010class M implements Runnable {
011        static int MIN = 0;
012        static int MAX = 100;
013        static int INIT = 50;
014        int x = INIT;
015        public void run () {
016                JSlider s = new JSlider(SwingConstants.VERTICAL, M.MIN, M.MAX, M.INIT);
017                /* ... */
018                s.addChangeListener(e -> {
019                        JSlider source = (JSlider)e.getSource();
020                        if (!source.getValueIsAdjusting()) {
021                                // the next two lines are redundant
022                                x = source.getValue();
023                                M.this.x = source.getValue();
024                        }
025                });
026        }
027}