Computer Science Canada Java Applets |
Author: | andrew. [ Tue Dec 09, 2008 7:41 pm ] | ||
Post subject: | Java Applets | ||
Hi guys, I recently started learning Java and have been checking out applets. The problem is that whenever I make an applet and I have the methods main and paint in there, paint is automatically executed and main is not. I think it may be because I've been programming on Mac or Linux and my friends have been programming on Windows, but still, there should be a way around it. Here is an example program:
EDIT: Also, I am using Eclipse in both Mac and Linux and when I don't run the program as an applet, it does main, but doesn't do paint. When I do run it as an applet, it doesn't do paint, but does main. |
Author: | [Gandalf] [ Tue Dec 09, 2008 7:46 pm ] |
Post subject: | RE:Java Applets |
In applications, main() is the entry point of the program, however Applets work differently. You won't be using a main(), but rather methods such as start() init() destroy() and paint(), which are inherited from the Applet class. http://java.sun.com/javase/6/docs/api/java/applet/Applet.html |
Author: | S_Grimm [ Tue Dec 09, 2008 7:49 pm ] | ||
Post subject: | Re: Java Applets | ||
First. Applications use "main" applets use "init" Second. Shouldn't matter what OS you program on, java is platform independent. Heres a snippet of code that uses Applets
Heres an application that uses JFrame Edit : Darn it. Gandalf beat me to it....... I hate having to search for files |
Author: | andrew. [ Tue Dec 09, 2008 7:51 pm ] |
Post subject: | RE:Java Applets |
Yeah, that was just sample code. My real applet has init, main, paint, action and a few others. Init, main, paint, and action should all run automatically. I know that when I run the program as an applet, paint, init, and action are all run, but when I run it as a program, only main is run. So Gandalf, where would I put my code I want to use first if I wanted to initialize all the elements in an array? Normally, I would do that in main. EDIT : So inside of applets, you don't need to use main? You can initialize things in init and draw things in paint? |
Author: | [Gandalf] [ Tue Dec 09, 2008 8:03 pm ] |
Post subject: | RE:Java Applets |
Yes. The control flow of an applet goes something like: init() -> start() -> paint() -> stop() -> destroy() Edit: Err, fixed. |