Java applets are classes written in Java which are intended not to run as stand-alone programs (as applications do) but as subprograms of a browser which is already managing a window.
|
Applets should NOT have main method but rather init, start, paint etc. for displaying on the browser window
|
The applet should be run through javac compiler getting a .class file as before: javac MyApplet.java
|
Also create an HTML file (say MyApplet.html) with an applet tag.
|
Two ways to run an applet:
-
If you have JDK on one's machine, one can run the applet with appletviewer
-
appletviewer MyApplet.html
-
Alternatively, run Netscape 2.0/3.0 or Internet Explorer essentially anywhere, point the browser at MyApplet.html, and applet is downloaded from the webserver and run by Java interpreter built into the browser. This requires that the .html and .class files are located in the document space of the web server.
|
This way we can compile on places with JDK installed but run almost anywhere!
|