# Three Steps to Making a Button Respond when Clicked
Suppose you have the following code:
```Java
public class MyFrame extends JFrame {
MyFrame() {
this.setSize(250,150);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton ok = new JButton("OK");
this.add(ok);
}
}
```
You want a message to flash up when the button is clicked. Follow these steps.
1) Make MyFrame implement ActionListener. _Don't forget to Fix Imports!_
```java
public class MyFrame extends JFrame implements ActionListener {
```
2) Override the actionPerformed method by adding the following code:
```java
public class MyFrame extends JFrame implements ActionListener {
MyFrame() {
this.setSize(250,150);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton ok = new JButton("OK");
this.add(ok);
}
public void actionPerformed(ActionEvent e) {
}
}
```
3) Don't forget to add an actionListener to your ok Button.
```java
JButton ok = new JButton("OK");
ok.addActionListener(this);
this.add(ok);
```
And that's it. Now you only need to add some code to your actionPerformed Method. You could just use a System.out.println("Button Clicked!"); but if you're feeling more adventurous, try
```java
JOptionPane.showMessageDialog(this, "Button Clicked!");
```
You might have to fix imports!
## Sample Code
```java
public class MyFrame extends JFrame implements ActionListener {
MyFrame()
{
this.setSize(250,150);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton ok = new JButton("OK");
ok.addActionListener(this);
this.add(ok);
}
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this, "Button Clicked!");
}
}
```