I would advise you to get your hands on a book. The best book might be Horstmann and Cornell, which you will probably find
here; I don’t think they have got the Java7 edition out yet. But you don’t need Java7 features. Find out about listeners.
What I can tell you is that your middle quote with the poorly indented code looks a mess. Even if you sort out the indentation, you end up with a load of
else ifs which make the method hard to maintain and also violate the design principle that
a method does one thing (acknowledgement: Fred Rosenberger). Your code looks as if you had been desperately writing something, anything, rather than taking the time to think about what to write and to design it.
Consider how you intend to draw one shape. Remember, you need to specify a size, colour and location as well as the type of shape. Start by drawing a square in a fixed location, and a fixed size. Once you have got that working, consider how to set its location. You obviously have some idea how to do that already. Then enhance it for colour and size.
You would do well to pass some sort of Square
via whichever Listener you use. There are several ways you can do it. Then you can draw and display it.
Search for my posts about how to write Listeners. They aren’t very recent, because I tend to refer to old posts rather than writing new ones. The instructions there are general, and not specifically related to your current problem.