JDK can compile both Java Applications and Applets. This document describes how to compile and execute a Java Applet. A Java Applet executes inside of a Web Browser. Java applets output to a rectangular region of a web browser. They can also open up additional windows outside of the browser.
|
This first step is to create a directory that will hold your Java project. Your Java project may have several files associated with it, so using a separate directory can help you keep organized. Start by opening a DOS window. Do this by selecting "command prompt" from the start menu. Use the command MD to create a directory to hold your project. Then use the command CD to change to that directory. You only need to use the command MD once to create your directory once. |
|
Now you need to create a short Java source file to compile and execute. Type the command notepad HelloWorld.java and you will see note pad pop up and ask if you would like to create the file. Say YES. |
|
Now key in a short simple Java Applet. |
|
Now you need to create a short HTML file to view the Applet in. Type the command notepad HelloWorld.html and you will see note pad pop up and ask if you would like to create the file. Say YES. |
|
Now key in a short simple HTML page to view the Applet. |
|
This applet can be viewed in two ways. You can view it using appletviewer by entering the command appletviewer HelloWorld.html. This will display the applet. |
|
This applet can be viewed in two ways. Secondly, you can view it using a browser by entering the command start HelloWorld.html. This will display the applet. NOTE: Generally only Applets that use JDK 1.1 and lower will work in most browsers. |