You could draw it all in an image and then copy that image (drawImage()) when it is time to render that object. But you don't have to use an image. The important thing is to render all of the pieces (the title and the rectangle) at the appropriate location whenever it is time to paint. So when your component is painting all of the subobjects, tell each object to paint itself and each objects paint method could be something like: public void paint(Graphics g) { g.setColor(textColor); g.drawString(titleText, titleLoc.x, titleLoc.y); g.setColor(rectColor); g.fillRect(rect.x, rect.y, rect.w, rect.h); }
Note that the dragging of objects is distinct from the rendering (or it can be, depending on your implementation). You could just track the mouse interaction manually and update the appropriate object locations based on those events. Then the ensuing paint events would use the updated locations.
There are a lot of ways to go about this, but hopefully this gives you some ideas.
Chet. Java2D
Eric Delacroix wrote:
Hi,
I'm fairly new in using Java draw. I'm trying to make an interface that permits to handle some graphical objects and link them between each other, with simple lines. The graphical object consists in a rectangle with a title at the top, a line to separate it from the rest of the rectangle, and that's all. But I'd like to be able to make some drag and drop of those objects, and so, I'd like to have this shape as one and only one object. Do I have to draw it in an "Image" object, or something else. I'm a little bit lost in this case, any help is welcome. Thank you Eric Delacroix
_________________________________________________________________ MSN Messenger : discutez en direct avec vos amis ! http://messenger.fr.msn.be
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".