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.
I've created six ellipses labelled p1, p2...up to p6. I'm trying to make it so that on a mouse click (if a p object is selected), an unfilled rectangle will be drawn around it. As a way of letting someone know the object was selected. I haven't had much luck. I don't want the rectangle to be drawn until the mouse event, and i've even tried drawing it first and then having it moved when a p object is clicked...still no luck. Any help would be great.
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copy of this thread.
As for your question: you need to do all your painting in your paint() or paintComponent() method. Instead of trying to draw the rectangle here in the event handler, instead have the event handler set a member variable that represents the selection, and have the paint method draw the selection if and only if it finds that member set.
This is a general principle: event handlers should modify a data model of some kind, while your painting method should render that model to the screen.
Thanks, got it working now...Sorry about double posting. I was in a huge rush before I left for work and needed some help. Also sorry about posting in the wrong forum. I'll try to be more considerate and obey the rules.
One more question if you don't mind. Once I create a drawing, like a rectangle on a mouse event (like clicking inside a circle). How would I go about getting rid of the rectangle if a click occurred outside the circle? Would I have to redraw it and set color to background color or can I destroy it somehow?