need help with AWT

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

need help with AWT

Satguru Shivastava
Hi EveryOne

Just trying to clear my AWT fundamentals.

The following is no big deal but keeps nagging me cause I seem to be
missing something.

I know that to draw on a component one needs to override the component
paint method
and issue the drawing cmds there.
What if one tries to draw from outside the paint method ?

I tried out the following code (under WIN 95 from an MSDOS window)

f=Frame()
f.setSize(200,200)
f.setVisible(1)
g=f.getGraphics()
g.drawRect(50,50,100,100)

When you run this u see the rectangle for a brief moment and then something
clears the frame.

You can see the rectangle if you put drawRect in a loop

f=Frame()
f.setSize(200,200)
f.setVisible(1)
g=f.getGraphics()
loop forever
 g.drawRect(50,50,100,100)
end

U can see it too if  if u switch focus to another window before drawing the
rectangle

f=Frame()
f.setSize(200,200)
f.setVisible(1)
g=f.getGraphics()
say 'Press enter to continue'
abc=ask
g.drawRect(50,50,100,100)

The frame is again cleared when u go back and click on the frame.

Wonder what clears the frame ?
I tried overriding the frame's paint,update, repaint methods by empty
methods
but got the same result.
(I get the same result in Java too.)
Would appreciate if somebody could throw light on this.

Thanx
Sat



                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                         
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>

Reply | Threaded
Open this post in threaded view
|

RE: need help with AWT

Patrick McPhee-3
> Satguru Shivastava ([hidden email]) wrote:
>
> I know that to draw on a component one needs to override the component
> paint method
> and issue the drawing cmds there.
> What if one tries to draw from outside the paint method ?
>
Something like this will happen:

> When you run this u see the rectangle for a brief moment and then
> something
> clears the frame.
>
> You can see the rectangle if you put drawRect in a loop
>
I bet it flickers, though.

> Wonder what clears the frame ?
>
Java does (or at least, the Java engine, or Windows in some
circumstances), then it calls either the paint or repaint method to
repaint it. The only places you can safely put things on the screen are
the paint, repaint, and update methods. If you want to do the work
involved in creating an image somewhere else, you can create an image in
a variable and then have the paint method write it to the window with
drawImage.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>

Reply | Threaded
Open this post in threaded view
|

Re: RE: need help with AWT

Satguru Shivastava
In reply to this post by Satguru Shivastava


Patrick McPhee <[hidden email]> wrote
 
>> You can see the rectangle if you put drawRect in a loop

>I bet it flickers, though.

On the contrary  I get a rock solid image and this on a 'poor mans pc'
(atleast by today's standards ) a  66 MHz  486 m/c :)
I guess AWT probably collapses the draw request

>> Wonder what clears the frame ?
 
>Java does (or at least, the Java engine, or Windows in some
>circumstances), then it calls either the paint or repaint method to
>repaint it.

Well
a. if it's going to clear it then why draw the rectangle in the first place
b. why not let the paint method decide if it want's to clear it or not.

Also
I thought awt called a component's paint method only when it believed that
the component was damaged.
Hmm..
Could it be that when one draw's on a component from outside the paint
method  then awt interprets that as damaging
the component...
But why clear it ?.
Ahh well .
I guess I just need to think things thru carefully.

Don't want to drag this any further , bet all of you have better things to
do than decipher my logic.:)

Thanks for the reply
Bye
Sat



                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
         
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>