Java Applets in Eclipse


Select File->New->Project->Java Project.. from the menu bar to begin creating your Java applet project. 

applet-8

For the project name, enter AppletTest, then click the Finish button. 

applet-9

After creating new project then display will be following screen.

applet-3

Your project called, "AppletTest" should now appear in the Package Explorer. To add a class to the package, single-click on "appletexample" with your mouse to select the package, then select File->New->Class from the menu bar.

applet-4

Create java class file under the package. After creating java class file then display the following screen.

applet-5

Create java applet code saving and compiling the applet program. Select File->Save  from the menu bar to save your work. If there are no syntax errors, you can now run the applet.

applet-6

To run the program, select the Welcome.java file, then select Run->Run as->Java Applet from the menu bar. The program runs and the the Java applet appears in the applet viewer.
 


This will bring-up the applet viewer


You can make the applet bigger by dragging the right-corner. This applet responds to mouse-clicks. Click your mouse over the black background in the viewer a few times. You will see a message displayed where you clicked


This applet also takes parameters passed by the HTML page. To see how to pass parameters to an applet, go to the next section.

This section assumes you understand how to run applets from the previous section. An HTML page can pass parameters to an applet. To run the Welcome applet from an HTML page, you would have the following in your HTML document

<applet class="Welcome.class">
<param name=MESSAGE value="Hello World!!">
</applet>
This particular applet displays the message "Welcome!!" as a default when no parameter was passed. This was the case in the previous section. This section will show you how to pass a parameter MESSAGE to the applet in Eclipse. Right-click (<ctrl&rt; + Mouse-click on the Mac) the file and select "Run...".


You will now have the Run Wizzard


Select "Java Applet" and New


You will be given the following window


Select "Parameters".


Now select "Add", to add a parameter. You must enter MESSAGE for the "Name" field. Enter anything you like on the "Value" field. Here is what I entered


You can add more parameters, although they will be ignored by this applet. When you are finished click Apply. Then click Run to run the applet. By clicking on the applets black background you will see your message