1) the MouseListener code should be part of the main() method.
2) then once you create the listener you need to add the listener to the frame.
I would suggest you read the section from the Swing tutorial on
How to Write a MouseListener for more information and a better example on how to write the code so that the GUI is created on the Event Dispatch
Thread.