Simple Applet in Java

by Mohan 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
mohan@localhost:-opt-lampp-htdocs-java_002.png

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
rsz_2simple_applet_-_mozilla_firefox_003.png



Tagged in:

911
like
0
dislike
0
mail
flag

You must LOGIN to add comments