List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create an action Action action = new AbstractAction("Action Label") { // This method is called when the action is triggered public void actionPerformed(ActionEvent evt) { Component c = (Component) evt.getSource(); // Get the frame Component frame = SwingUtilities.getRoot(c); // Hide the frame frame.setVisible(false);//from w w w . j av a 2s.co m } }; }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }/*from w w w . j av a 2 s . co m*/ }); jb.doClick(1000); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }// w w w. java 2s . c o m }); jb.doClick(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }/* w w w .j a va 2 s . c om*/ }); System.out.println(jb.getActionCommand()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }//w ww .j a v a 2 s .c o m }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }/*from w w w. ja v a2 s . c o m*/ }); System.out.println(jb.getAction()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Action action = new AbstractAction("CheckBox Label") { // called when the button is pressed public void actionPerformed(ActionEvent evt) { JCheckBox cb = (JCheckBox) evt.getSource(); // Determine status boolean isSel = cb.isSelected(); if (isSel) { // selected } else { // deselected }// w w w. j a v a2s. com } }; // Create the checkbox from the action JCheckBox checkBox = new JCheckBox(action); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }//from w ww . j a v a2s.co m }); ActionListener[] lis = jb.getActionListeners(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JOptionPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Object response = JOptionPane.showInputDialog(source, "Choose One?", "JOptionPane Sample", JOptionPane.QUESTION_MESSAGE, null, new String[] { "A", "B", "C" }, "B"); System.out.println("Response: " + response); }/*from w w w. j av a 2s . c om*/ }; button.addActionListener(actionListener); f.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:NoButtonPopup.java
public static void main(String args[]) { JFrame frame = new JFrame("NoButton Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); int response = JOptionPane.showOptionDialog(source, "", "Empty?", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {}, null); System.out.println("Response: " + response); }// w w w . jav a2 s . c o m }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }