Wednesday, November 9, 2011

Running a JAVA applet program

This is to test if JAVA is installed properly. A Java applet program which is compiled without using and IDE. The procedure is as follows

Applet Hello world
Running it from the console without any IDE

A. Creating a class extending the applet class
1. open your favourite editor and type in the following code
public class HWApplet extends java.applet.Applet
{
    public void paint(java.awt.Graphics g)
    {
        g.drawString("greetings",50,50);
    }
}
2. Save the file as HWApplet.java

B. Creating a HTML file to run the applet

1. Open your editor and type in the following code
<APPLET code="HWApplet.class" width=350 height=200></APPLET>
2. Save it as HW.html in the same directory as the HWApplet.java file

C. Compile the Java program
1. you can compile the Java program by going into the folder containing the file and using Javac
javac HWApplet.java

D. Running the Applet

1. Open your browser and make sure you have JRE installed and enabled. look here on details how to enable JAVA in your browser
http://www.java.com/en/download/help/enable_browser.xml
2. Open the previously created HW.html file in the browser. it should display a "greetings" message

Running a JAVA applet in firefox
1. make sure you have installed the Java Runtime Environment
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
2. In firefox -> tools -> Add-ons -> Plugins make sure the Java plugin is enabled

No comments:

Post a Comment