[2362] in java-interest
Re: When does a graphics class get added to?
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Fri Sep 29 20:04:32 1995
Date: Fri, 29 Sep 1995 14:28:19 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: Elliotte@blackstar.com
Cc: java-interest@java.Eng.Sun.COM
Hi Elliotte,
> I think the follwoing code demonstrates a fundamental
> misunderstanding I have about applets. I'd appreciate it if someone
> would explain to me what I'm doing wrong.
>
> 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
> mouse moved). However it seems the only event I ever get is a paint
> event. Furthermore if I obscure a window and then unobscure it, I
> only get that paint event and any previous graphics that weren't
> obscured.
>
> Does the Graphics context of an applet not store what has
> gone before? i.e. do I need to keep the contents of a Graphics pane
> in a separate data structure and then redraw the entire data
> structure any time I get a paint event?
>
> If that's the case is there any clipping done so I only redraw those
> parts of an applet that were obscured?
Try this instead:
import java.awt.*;
public class Applet2 extends java.applet.Applet {
String str = "";
public boolean handleEvent(Event evt) {
str = evt.toString();
repaint();
return true;
}
public void paint(Graphics g) {
g.drawString(str, 0, size().height * 2 / 3);
}
}
Have fun,
Arthur van Hoff
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com