STEP 6: Create and Execute a Java Applet

กก

1. Select File > New > Project and a NewProject window will pop up, select Java Project, then click Next button.

2. New Java Project window will pop up, input the name of project, here "AppletDemo", then click Next button.

3. Keep it as default and click Finish button.

4. Select AppletDemo (project name) in the workspace and right click on it, then select New > File.

5. In the pop up window New File, input the name of applet, here "SimpleApplet.java", then click Finish button.

6. Add the following code to the file SimpleApplet.java and save it.

import java.awt.*;
import java.applet.*;

public class SimpleApplet extends Applet
{
    public void paint(Graphics g)
    {
       g.setColor (new Color(0,0,255));
       g.drawString("This is a simple applet Demo", 50,50);
    }

}

7.Select SimpleApplet.java in the workspace and right click it, then select Run>Java Applet.

8. A AppletViewer window will pop up showing the running result.

9. Applet can also be viewed through a browser, to do this, you need edit a html file that contains the applet tag and applet class name (the applet class should be in the same directory, or else path should be included). Here is a example (in FrontPage editor).

10. Click the html file and the applet will show as below.

กก

กก

กก