What happens if you have more than one component being listened to?
The following code produces the following JFrame. If you click on Button One a message appears saying Button One pressed. Something similar happens if you click Button Two
![[oneandtwobuttons.png]]
```Java
package guitwobuttons;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author ajb
*/
public class GUITwoButtons extends JFrame implements ActionListener{
JButton btnOne, btnTwo;
GUITwoButtons() {
this.setSize(100,100);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
btnOne = new JButton("One");
btnTwo = new JButton("Two");
btnOne.addActionListener(this);
btnTwo.addActionListener(this);
this.add(btnOne);
this.add(btnTwo);
this.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new GUITwoButtons();
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == btnOne)
{
JOptionPane.showMessageDialog(this, "Button One Pressed");
}
else if (ae.getSource() == btnTwo)
{
JOptionPane.showMessageDialog(this, "Button Two Pressed");
}
}
}
```