This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The Reference to Graphics (g) in paint() is currently scoped only to that method. Outside of paint(), the other methods have no idea what g refers to. Two quick ways to fix this would be to either create a global variable that holds a reference to g:
Or, change vertical and horizontal to accept an additional argument of 'Graphics', and then use that reference in each of the methods. Hope this helps.
Personally, I prefer Jason's second suggestion: add a Graphics object as a parameter to the vertical() and horizontal() methods. Having a "global" Graphics object (technically, it's a instance variable, but that's another topic altogether), means that the Graphics object still has a reference to it after the paintMethod() has finished. There are a couple of problems with this: 1) the object is not eligible for garbage collection and 2) there is the potential for another method to use this "stale" Graphics object outside of the Swing event mechanism. For example, another class could call vertical() or horizontal() directly which would probably have bad results.
Well, I'll quit rambling. Let us know how things work out.