The problem is that button1 is a local variable. You could do it by just change the way you add the actionListener.
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//button is pressed
System.out.println("You clicked the button");
}});
Or you make button1
a global variable.