Java Action .removePropertyChangeListener (PropertyChangeListener listener)
Syntax
Action.removePropertyChangeListener(PropertyChangeListener listener) has the following syntax.
void removePropertyChangeListener(PropertyChangeListener listener)
Example
In the following code shows how to use Action.removePropertyChangeListener(PropertyChangeListener listener) method.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/* w w w . j ava 2s. c o m*/
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String[] a) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Action action = new ShowAction();
JButton button = new JButton(action);
frame.add(button, BorderLayout.CENTER);
frame.setSize(350, 150);
frame.setVisible(true);
}
}
class ShowAction extends AbstractAction {
public ShowAction() {
super("About");
PropertyChangeListener lis = new PropertyChangeListener(){
@Override
public void propertyChange(PropertyChangeEvent e) {
System.out.println(e);
}
};
addPropertyChangeListener(lis);
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_A));
putValue(Action.NAME, "Go to number ");
putValue(Action.LONG_DESCRIPTION, "Change the number to ");
removePropertyChangeListener(lis);
}
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("About Swing");
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »