a) Please wrap your code in the code tags
b) For writing the action from your first post, see How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event...