Java Applets in Eclipse

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


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


After creating new project then display will be following screen.


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.


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


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.


To run the program, select the 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!!">
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