View Full Version : applet question...
inkedmn
09-08-2002, 06:12 PM
ok, so i'm doing an applet for my java class. everything works fine, except for one thing. as soon as the applet is finished running (i.e., i hit "ok" on the last window), it immediately starts again from the beginning.
our teacher said that this is because the "paint" method will be called by the browser every few seconds, and that i should rename the method "init". i tried this, and the applet doesn't run.
any ideas?
Dru Lee Parsec
09-09-2002, 12:31 PM
our teacher said that this is because the "paint" method will be called by the browser every few seconds, and that i should rename the method "init".
WRONG!
Once again we've caught your teacher in a big mistake.
In a Java application the entry point to the program is the main method. In a Java applet the entry point is the init method. So the init method is called only once as the applet is being "constructed".
The excuse about the paint method being called every few seconds is bullshit. The pain method is called when :
1. The operating system determines that all or part of the applet is invalid and must be repainted (as in when a dialog box obsucures part of the applet and then is removed)
2. When you explicitly call the paint method.
3. When one of the individual components in your applet changes it's appearence and must be repainted (changing the text of a JLable with setText(String) for example ).
Email your original code to me at work. I'll take a look at it (or just attach it here). We'll find out what he's missing.
inkedmn
09-09-2002, 01:09 PM
dru,
here's my code...
thanks for looking at it :)
Dru Lee Parsec
09-09-2002, 01:21 PM
Change this line
public void init( Graphics g ) {
to this
public void init() {
and the applet will work.
The JRE wants to call the init method with no arguments as the entry point to the program. It doesn't understand an init method with a Graphics parameter.
When I make that change it seems to run just fine under JDK 1.3.1
inkedmn
09-09-2002, 01:27 PM
it sure did, you da man :)
thanks for the assist, Greg. :D
gufmn
09-09-2002, 01:53 PM
w00t! Mine's fixed as well. Dru is da shiznit!
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.