List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
From source file:Main.java
public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); b.setText(""); source.setText("Drag and drop me to the following JButton"); }
From source file:PersisTest.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { // Repaint with an empty display list. displayList = new ArrayList(); repaint();//from w w w. j a v a 2 s . com } else if (e.getSource() == saveBtn) { // Write display list array list to an object output stream. try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (IOException ex) { System.err.println("Trouble writing display list array list"); } } else if (e.getSource() == restoreBtn) { // Read a new display list array list from an object input stream. try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (ArrayList) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (ClassNotFoundException ex) { System.err.println("Trouble reading display list array list"); } catch (IOException ex) { System.err.println("Trouble reading display list array list"); } } else if (e.getSource() == quitBtn) { System.exit(0); } }
From source file:Main.java
public Main(JFrame frame) { analyzer = new MyDialog(frame); analyzer.pack();/*from w w w . j a va 2s. c o m*/ analyzer.setLocationRelativeTo(frame); Point location = analyzer.getLocation(); location = new Point(location.x - LOC_SHIFT, location.y - LOC_SHIFT); analyzer.setLocation(location); analyzer.setVisible(true); add(new JButton(new AbstractAction(DISABLE_DIALOG_COMPONENTS) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG_COMPONENTS)) { btn.setText(ENABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(false); } else { btn.setText(DISABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(true); } } })); add(new JButton(new AbstractAction(DISABLE_DIALOG) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG)) { btn.setText(ENABLE_DIALOG); analyzer.setEnabled(false); } else { btn.setText(DISABLE_DIALOG); analyzer.setEnabled(true); } } })); }
From source file:ComboBoxDemo2.java
public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); String newSelection = (String) cb.getSelectedItem(); currentPattern = newSelection;/*from w ww . j a v a 2s . c o m*/ reformat(); }
From source file:com.db2eshop.gui.component.tab.menu.TabRightClickPopupMenu.java
/** {@inheritDoc} */ @Override/*from www . j ava2 s.c o m*/ public void actionPerformed(ActionEvent arg0) { if (add.equals(arg0.getSource())) { log.info("Add"); addDialog.showDialog(table); } unsetVolatile(); }
From source file:Ventanas.VentanaVerGrafico.java
public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (o == botonVolverVerGrafica) { this.setAlwaysOnTop(false); this.setVisible(false); }/*from ww w. j ava 2s. c o m*/ }
From source file:SimpleMouse.java
/** * Use the action event of the exit button to end the application. *//*from w ww . j ava 2 s. c o m*/ public void actionPerformed(ActionEvent e) { if (e.getSource() == exitButton) { dispose(); System.exit(0); } }
From source file:JumbledImage.java
public void buildUI() { final JumbledImage ji = new JumbledImage(imageSrc); add("Center", ji); JButton jumbleButton = new JButton("Jumble"); jumbleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); ji.jumble();//from w ww . j a va 2s. com ji.repaint(); }; }); Dimension jumbleSize = ji.getPreferredSize(); resize(jumbleSize.width, jumbleSize.height + 40); add("South", jumbleButton); }
From source file:AlphaCompositeDemo.java
public AlphaCompositeDemo() { super();/*w w w. j a v a2 s . co m*/ Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); rulesBox = new JComboBox(rulesLabels); rulesBox.setSelectedIndex(0); rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT); rulesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.compositeRule = rules[cb.getSelectedIndex()]; canvas.repaint(); } }); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(25); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); canvas.alphaValue = (float) slider.getValue() / 100; canvas.repaint(); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); panel.add(rulesBox); panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT)); panel.add(slider); container.add(panel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(500, 300); setVisible(true); }
From source file:com.db2eshop.gui.dialog.ConfirmDialog.java
/** {@inheritDoc} */ @Override//from www .j a va 2s .c o m public void actionPerformed(ActionEvent e) { if (confirmButton.equals(e.getSource())) { try { onConfirm(); this.setVisible(false); } catch (Exception exception) { onError(exception); } } }