Where do you add an action listener to the button? That is the connection needed for the button to be able to call your code. When it gets an ActionEvent, it calls the action listeners that have been added to it.