Example usage for javax.swing AbstractButton addActionListener

List of usage examples for javax.swing AbstractButton addActionListener

Introduction

In this page you can find the example usage for javax.swing AbstractButton addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

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());
        }// www. ja  v a 2s  .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());
        }//from   ww  w  . j  a  v  a2  s.c om
    });
    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());
        }/*from  ww w  .  j av  a 2  s  .c o m*/
    });
    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());
        }//from w ww. j  av a2s .co 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());
        }/*  www  . ja  v  a  2  s.  c om*/
    });
    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[] args) {
    AbstractButton jb = new JButton("Press Me");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.out.println(((JComponent) arg0.getSource()).getFont());
        }//from ww  w .j a va2  s  . c  o 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:MultiClickThreshholdDemo.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    AbstractButton bn = new JButton();
    bn.setMultiClickThreshhold(1000);/*from  w w  w.j a va2 s .  c o  m*/

    bn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action");
        }
    });

    frame.add(bn);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);/*from  w ww.  j  a va 2 s  . c om*/
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JButton button = new JButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ASelectedButton.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Radio Buttons");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);/*from   ww w.  j a  v a 2  s  .c o m*/
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JToggleButton button = new JToggleButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void addActionListener(ActionListener listener, AbstractButton... buttons) {
    for (AbstractButton button : buttons) {
        button.addActionListener(listener);
    }/*from   w ww .j a v  a 2 s.c  o m*/
}