JToggleButton: addActionListener(ActionListener l) : JToggleButton « javax.swing « Java by API






JToggleButton: addActionListener(ActionListener l)

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JToggleButton;

public class MainClass {
  public static void main(String[] args) {
    JToggleButton jtb = new JToggleButton("Press Me");
    jtb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ev) {
        System.out.println("ActionEvent!");
      }
    });
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = f.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(jtb);
    f.pack();
    f.setVisible(true);
  }
}

           
       








Related examples in the same category

1.new JToggleButton(String text)
2.JToggleButton: addChangeListener(ChangeListener)
3.JToggleButton: addItemListener(ItemListener lis)