[2409] in java-interest

home help back first fref pref prev next nref lref last post

Re: When does...

daemon@ATHENA.MIT.EDU (Francis Van Aeken)
Sat Sep 30 15:10:26 1995

From: Francis Van Aeken  <Francis.Van-Aeken@imag.fr>
Date: Sat, 30 Sep 1995 18:16:51 +0100
To: Elliotte@blackstar.com
Cc: Francis.VanAeken@imag.fr, java-interest@java.sun.com

Hi Elliotte,

My comments are for alpha Java - I haven't had a look at the beta yet -
should be similar.

>The goal is to be able to print a string into the applet window with 
>the name of the event whenever the applet receives an event (like 

In general, you should do all on-screen drawing in the paint() method -
actually, it is one of the few methods in Applet that has the needed
Graphics g argument.

For example, the mouseUp() method in the Applet class has no Graphics g
argument, so you cannot do any direct drawing there.
In mouseUp() you need to register the event in an instance variable you have
defined, then you have to call repaint().
Repaint() will have paint() called as soon as possible.
In paint() you check your instance variable and draw, for example, the
name of the event. If you want to keep a history of all events, you *have*
to store them in a list (e.g. in an instance of Vector) and have the
complete list drawn in paint().
Yes, you redraw the complete list every time you catch an event and call
repaint(). Doesn't sound very efficient? It isn't, but this is how you should
start. Later, you can add lots of 'cleverness' and do selective redrawing (cf.
clipping, see below).
The mouseUp(Graphics g) method you coded does not override mouseUp(int x,
int y) since they have a different signature (in this case, different
argument list) and are considered completely different functions.
Consequently, your mouseUp() never gets called...

Having all drawing executed in one method is standard practice
in event-driven programming. Since not only you, but also the window
manager generates repaint events, any other approach would lead to
(even more) chaos.

>If that's the case is there any clipping done so I only redraw those 
>parts of an applet that were obscured?

Clipping indeed occurs. Off course, all the code in paint() is executed:
if you want to take advantage of clipping, *you* have to handle clipping
in your drawing code yourself.
  
Cheers, F.
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post