Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Code Block
languagejava
titleSpecial ActionListener
public class MySpecialButtonListenerMySpecialActionListener implements ActionListener {
	
	public void actionPerformed(ActionEvent e) {
		// Do something special	
	}
}
 
public class SomeClass implements ActionListener {
	
	button1.addActionListener(this);
	button2.addActionListener(this);
	specialButton.addActionListener(new MySpecialButtonListenerMySpecialActionListener);
 
	public void actionPerformed(ActionEvent e) {
		// Do something
	}
}
 
 
 

 

 

Code Block
languagejava
titleAnonymous ActionListener
public class SomeClass implements ActionListener {
 
	button1.addActionListener(this);
	button2.addActionListener(this);
	specialButton.addActionListener(
		new ActionListener() { 
			public void actionPerformed(ActionEvent e) {
		        // Do something special
    		}
		}
	);
 
	public void actionPerformed(ActionEvent e) {
		// Do something
	}
}

 

...