Simple Applet in Java
by Mohan[ Edit ] 2014-02-21 12:38:49
Simple Applet in Java
First Create Java file
//Import java files
import java.applet.Applet;
import java.awt.*;
//The applet code starts
public class FirstApplet extends Applet {
public void paint(Graphics g) {
g.drawRect(100,150,250,100);
g.fillRect(100,150,250,100);
g.setColor(Color.red);
g.drawString("SIMPLE JAVA APPLET!",150,180);
}
}
and save the code as FirstApplet.java
Before compiling set the class path for the FirstApplet.java file.
Then compile the file using the following command
Then create a Html file to display applet on browser
<html>
<head>
<title>
Simple Applet
</title>
</head>
<body>
<applet code="FirstApplet.class" width="400" height="400" ></applet>
</body>
</html>
Then run the html file on browser. You will get the output as