Sounds like what you need to learn about is event handling in Java. Start with Sun's tutorial,
http://java.sun.com/docs/books/tutorial/index.html, and you'll find something useful I'm sure.
Edit:
In fact,
http://onesearch.sun.com/search/clic...ve&col=javadoc is the page that covers event handling and graphics. Should be a good starting point.