In a simple situation like a number of JButtons on a JPanel there are two ways to implement an ActionListener.
1. on the panel
[tt]class MyPanel extends JPanel implements ActionListener[/tt]
then set action commands for each button, add actionListener(this) to each button, and in the actionPerformed() work out which button was pressed by looking at the ActionEvent's action command.
2. on the buttons
add a seperate ActionListener to each button with the code that it has to run
Personally I prefer the second method as the action is attached to the button that triggers it. Are there other considerations involved? or is it just a matter of personal style? [sig]<p> <br><a href=mailto: > </a><br><a href= home</a><br> [/sig]
1. on the panel
[tt]class MyPanel extends JPanel implements ActionListener[/tt]
then set action commands for each button, add actionListener(this) to each button, and in the actionPerformed() work out which button was pressed by looking at the ActionEvent's action command.
2. on the buttons
add a seperate ActionListener to each button with the code that it has to run
Personally I prefer the second method as the action is attached to the button that triggers it. Are there other considerations involved? or is it just a matter of personal style? [sig]<p> <br><a href=mailto: > </a><br><a href= home</a><br> [/sig]