Example usage for javax.swing JButton addItemListener

List of usage examples for javax.swing JButton addItemListener

Introduction

In this page you can find the example usage for javax.swing JButton addItemListener.

Prototype

public void addItemListener(ItemListener l) 

Source Link

Document

Adds an ItemListener to the checkbox.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    JButton jb = new JButton("Press Me");

    jb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            System.out.println("ItemEvent!");
        }/*from   w w  w .j  a va  2 s  .c o  m*/
    });

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);
    f.pack();
    f.setVisible(true);
}