Re: Weird Problem in using MouseListener
From: Matt Humphrey (matth_at_ivizNOSPAM.com)
Date: 02/03/04
- Next message: Andrew Thompson: "Re: Sun Forte / ONE Community Edition class lib ?"
- Previous message: Juergen Kreileder: "Re: BigInteger on 64 bit platform"
- In reply to: Minti: "Weird Problem in using MouseListener"
- Next in thread: Ian Shef: "Re: Weird Problem in using MouseListener"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 2 Feb 2004 22:01:46 -0500
"Minti" <mintiSPAMBLOCK@yahoo.com> wrote in message
news:e87fc4b0.0402021802.7f5fcc26@posting.google.com...
> Hi there all, I am having a weird problem in the following Applet
> code,
>
> <begin code>
<snip code>
> The problem is that when the applet is running, whenever mouse is
> clicked the applet shows MouseRelasedMouseClicked, even though I set
> the msg to "" whenever paint is called, the line with
> System.out.println(msg) in mouseReleased() shows that somehow the call
> to repaint() just did not occur, Am I missing any point on how the
> paint method works.
Yes, you're missing the point. Repaint does not call paint. Repaint informs
the rendering system that a particular region needs to be updated. You can
call repaint many times and the region may be marked only once. (In fact, if
the region is obscured it may not even get repainted at all, which is why
paint shouldn't have side-effects.) Moreover, the mouse events are occuring
in the UI thread, which is also used for painting. The painting will occur
at best after the current events are finished--you really wouldn't want to
deal with the complexity of an action thread running in parallel with your
painting thread. Finally, part of the explanation of your result is that
while mousePressed and mouseClicked say msg += " more message", the
mouseReleased handler simply says msg = "mouseReleased", which makes it drop
the mouse pressed message.
> I belive it is possibly because of the paint queue, that might be
> maintained and from which only the most recent call to paint is
> executed.
There is no paint queue. Painting is done from the same UI thread that
handles event dispatching.
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
- Next message: Andrew Thompson: "Re: Sun Forte / ONE Community Edition class lib ?"
- Previous message: Juergen Kreileder: "Re: BigInteger on 64 bit platform"
- In reply to: Minti: "Weird Problem in using MouseListener"
- Next in thread: Ian Shef: "Re: Weird Problem in using MouseListener"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|