List of usage examples for javax.swing.event ChangeEvent getSource
public Object getSource()
From source file:BoundedChangeListener.java
public void stateChanged(ChangeEvent changeEvent) { Object source = changeEvent.getSource(); if (source instanceof JProgressBar) { JProgressBar theJProgressBar = (JProgressBar) source; System.out.println("ProgressBar changed: " + theJProgressBar.getValue()); } else {//from w w w.ja v a 2s . com System.out.println("Something changed: " + source); } }
From source file:BoundedChangeListener.java
public void stateChanged(ChangeEvent changeEvent) { Object source = changeEvent.getSource(); if (source instanceof BoundedRangeModel) { BoundedRangeModel aModel = (BoundedRangeModel) source; if (!aModel.getValueIsAdjusting()) { System.out.println("Changed: " + aModel.getValue()); }//from w w w. j a va 2 s.co m } else if (source instanceof JSlider) { JSlider theJSlider = (JSlider) source; if (!theJSlider.getValueIsAdjusting()) { System.out.println("Slider changed: " + theJSlider.getValue()); } } else { System.out.println("Something changed: " + source); } }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider slider = new JSlider(); BoundedRangeModel model = slider.getModel(); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { BoundedRangeModel m = (BoundedRangeModel) e.getSource(); System.out.println("Slider position changed to " + m.getValue()); }/*from w w w . j a v a 2s. co m*/ }); getContentPane().add(slider); pack(); }
From source file:Main.java
public void stateChanged(ChangeEvent changeEvent) { Object source = changeEvent.getSource(); if (source instanceof BoundedRangeModel) { BoundedRangeModel aModel = (BoundedRangeModel) source; if (!aModel.getValueIsAdjusting()) { System.out.println("Changed: " + aModel.getValue()); }//w ww .j av a 2s .c o m } else if (source instanceof JSlider) { JSlider theJSlider = (JSlider) source; if (!theJSlider.getValueIsAdjusting()) { System.out.println("Slider changed: " + theJSlider.getValue()); } } else if (source instanceof JProgressBar) { JProgressBar theJProgressBar = (JProgressBar) source; System.out.println("ProgressBar changed: " + theJProgressBar.getValue()); } else { System.out.println("Something changed: " + source); } }
From source file:SineDraw.java
public Main() { super(new BorderLayout()); add(BorderLayout.CENTER, sines); adjustCycles.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sines.setCycles(((JSlider) e.getSource()).getValue()); }//from w ww. j a v a 2s . c o m }); add(BorderLayout.SOUTH, adjustCycles); }
From source file:Main.java
public void makeUI() { String[] zones = { "Asia/Tokyo", "Asia/Hong_Kong", "Asia/Calcutta", "Europe/Paris", "Europe/London", "America/New_York", "America/Los_Angeles" }; JLabel[] labels = new JLabel[zones.length]; SimpleDateFormat[] formats = new SimpleDateFormat[zones.length]; JFrame frame = new JFrame(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();//from w ww. j a v a 2 s .c om SpinnerDateModel model = new SpinnerDateModel(); model.setValue(date); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Date date = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(date)); } } }); SimpleDateFormat format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); JPanel panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout()); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:GrayModel.java
public void stateChanged(ChangeEvent e) { JSpinner mySpinner = (JSpinner) (e.getSource()); GrayModel myModel = (GrayModel) (mySpinner.getModel()); setBackground(myModel.getColor());//w w w . ja va2 s . c o m updateToolTipText(mySpinner); }
From source file:it.unibas.spicygui.vista.listener.SliderChangeListener.java
public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { double confidence = (double) source.getValue() / 100; for (Widget connectionWidget : connectionLayer.getChildren()) { ConnectionInfo connectionInfo = (ConnectionInfo) connectionLayer .getChildConstraint(connectionWidget); if (connectionInfo != null) { if (connectionInfo.getConfidence() < confidence) { connectionWidget.setVisible(false); scene.validate();/*from ww w . j a va2s . com*/ } else { connectionWidget.setVisible(true); scene.validate(); } } } } }
From source file:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java
public void stateChanged(ChangeEvent e) { if (e.getSource() == slider) { int value = this.slider.getValue(); spinner.setValue(value);/*from ww w . j a v a 2s . co m*/ switchColumn(value); } else { int value = (Integer) this.spinner.getValue(); slider.setValue(value); switchColumn(value); } }
From source file:ColorComposite.java
public ColorComposite() { super();//from ww w. j ava2s . co m Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); JPanel panel = new JPanel(); JLabel label = new JLabel("Color-Composite: "); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 65); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider tempSlider = (JSlider) e.getSource(); alphaValue = (float) (tempSlider.getValue() / 100.0); textField.setText(Float.toString(alphaValue)); canvas.repaint(); } }); textField = new JTextField("0.65", 4); panel.add(label); panel.add(slider); panel.add(textField); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(450, 450); setVisible(true); }