Simple Java Applet

Below you will find the Java code for creating a simple applet. Next step is to add and applet to your webpage. To do this simple copy the .class file into your directory and insert the following code:

<APPLET CODE=TestApplet.class WIDTH=200 HEIGHT=100> </APPLET> The applet will then be displayed as follows: The Java code for the above applet:

import java.applet.Applet;
import java.awt.Graphics;
public class TestApplet extends Applet {
    StringBuffer buffer;
    public void init() {
	buffer = new StringBuffer();
	 System.out.println("HelloWorld (Console)");
	 buffer.append("HelloWorld (Applet)");
     repaint();
    }
    public void paint(Graphics g) {
	//Draw a Rectangle around the applet's display area.
        g.drawRect(0, 0, size().width - 1, size().height - 1);
	//Draw the current string inside the rectangle.
        g.drawString(buffer.toString(), 5, 15);
    }
}

Related Articles

SAP Java development - Example code and information on various areas of Java development
Introduction to Java Applet development
AWT Java development
Java code to implement close functionality into AWT design
Java code to implement close functionality into AWT design
Simple steps to setting up your SAP Java development environment
Configuring your java development platform
Create simple Java Application ('Hello world”)
Install SAP Netweaver development studio
Introduction
SAP Netweaver development studio
SAP Netweaver development studio is based on Eclipse
Code of simple Swing Java Applications
Code of simple Swing Java Applications
Simple Swing Java Applet
Java Swing development
Code of simple Swing Java Applications
Java swing code for creating a simple tree