List of usage examples for javax.swing.event ChangeEvent getSource
public Object getSource()
From source file:Main.java
public static void main(String[] argv) throws Exception { JSlider slider = new JSlider(); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider slider = (JSlider) evt.getSource(); if (!slider.getValueIsAdjusting()) { int value = slider.getValue(); System.out.println(value); }//from w w w.ja va 2 s .c om } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTabbedPane pane = new JTabbedPane(); pane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JTabbedPane pane = (JTabbedPane) evt.getSource(); int sel = pane.getSelectedIndex(); System.out.println(sel); }/* w ww.jav a 2 s.c om*/ }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int minimum = 0; int maximum = 100; JProgressBar progress = new JProgressBar(minimum, maximum); progress.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JProgressBar comp = (JProgressBar) evt.getSource(); int value = comp.getValue(); int min = comp.getMinimum(); int max = comp.getMaximum(); }//from w ww . jav a 2s . c o m }); }
From source file:RegisterChangeListenerToJSlider.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL, 10, 100, 20); framesPerSecond.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int fps = (int) source.getValue(); System.out.println(fps); }/*from w w w . j av a2 s. com*/ } }); frame.add(framesPerSecond, "North"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MenuSelectionManager.defaultManager().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MenuSelectionManager msm = (MenuSelectionManager) evt.getSource(); MenuElement[] path = msm.getSelectedPath(); if (path.length == 0) { }/*from www .j a va2 s . c o m*/ } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MenuSelectionManager.defaultManager().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MenuSelectionManager msm = (MenuSelectionManager) evt.getSource(); MenuElement[] path = msm.getSelectedPath(); if (path.length == 0) { }//from w w w . java2s .c o m } }); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }/*from w w w . j ava 2 s . co m*/ }; SpinnerModel model3 = new SpinnerNumberModel(); JSpinner spinner3 = new JSpinner(model3); spinner3.addChangeListener(listener); frame.add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }//from ww w .ja v a 2 s. c o m }; SpinnerModel model3 = new SpinnerNumberModel(); JSpinner spinner3 = new JSpinner(model3); spinner3.addChangeListener(listener); ChangeListener[] changeListeners = spinner3.getChangeListeners(); frame.add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame frame = new JFrame(); Calendar now = Calendar.getInstance(); Calendar earliest = (Calendar) now.clone(); earliest.add(Calendar.MONTH, -6); Calendar latest = (Calendar) now.clone(); latest.add(Calendar.MONTH, 6); SpinnerModel model = new SpinnerDateModel(now.getTime(), earliest.getTime(), latest.getTime(), Calendar.WEEK_OF_YEAR); final JSpinner spinner = new JSpinner(model); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println(((SpinnerDateModel) e.getSource()).getDate()); }/*www . ja v a 2s . c om*/ }); frame.getContentPane().add("North", new JLabel("Choose a week")); frame.getContentPane().add("Center", spinner); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }//from w w w. ja v a 2 s . co m }; spinner1.addChangeListener(listener); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90); frame.setVisible(true); }