Are you asking how to write an action listener to respond to presses to a button?
See the tutorial: How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing...