Click to See Complete Forum and Search --> : fixed modal dialog


thanasis
November 25th, 2004, 06:24 AM
Hi to everyone,



i am writing an awt applet. When someone clicks on a button a confirmation "yes/no" dialog pops up. When the user drags (moves) the dialog from its title bar and drops it inside the drawing panel (which contains drawings i.e circles,ovals,lines etc.) , the panel contents are erased (destroyed).
Does anyone know how can I make this dialog fixed so that the user couldn't move it?
Or if that isn't possible, is there a way to protect my panel's drawings (lines, circles etc) from being lost when the dialog lies inside the panel?

thanks in advance
thanasis

dlorde
November 26th, 2004, 10:55 AM
Dragging stuff over your drawing shouldn't delete anything... The drawing code should be in the paint(...) method of the panel so that it gets redrawn by the system every time it is necessary. The system will call the paint(...) method whenever part of the panel needs redrawing.

Your applet should store everything that the panel's paint(...) method needs to redraw the picture. Have a browse through Methods For Drawing (http://java.sun.com/docs/books/tutorial/applet/overview/componentMethods.html).

Somtimes the simple stuff takes more work than you think...

cjard
November 26th, 2004, 11:40 AM
or, in other words; it sounds ike youre drawing on the graphics context directly, and when ANYTHING passes over that region, your drawing effort will be lost (the system will realise that the panel is dirty and needs re-drawing, so it invokes the paint() method, which you have not over-ridden; paint()'s default action is to paint the background, nothing else)

dlordes suggestion of storing what you want to draw is a good idea; it sure makes saving it to disk more easy anyway.
either, draw to an offscreen buffer, then use the paint() method to copy the data onto the screen, or insert objects into a storage container of some kind, like a Linked List.. you can store objects, points, lines, pictures, etc.. anything that can draw itself. iterating through the lsit from the start will redraw everything. this approach makes Undo an easy thing to implement, but refreshing the image takes longer as pixels may be painted several times