24 July 2009

Embedding Applets in a Web page - 1

Setup the WampServer as explained here
-----------------HelloWorldApplet.java-----------------
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class HelloWorldApplet extends Applet{
public static void main(String[] args){
Frame frame = new Frame("Roseindia.net");
frame.setSize(400,200);
Applet app = new HelloWorldApplet();
frame.add(app);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
g.drawString("Hello World!",200,100);
}
}
-------------------------------------------------------
-----------------------test.html-----------------------
<html>
<head>
<title>A Simple Applet program</title>
</head>
<body>
<APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500>
</APPLET>
</body>
</html>
-------------------------------------------------------


-------------------------------------------------------
1. Save HelloWorldApplet.java and test.html inside the website's home page
2. Make sure JRE is installed in the machine.
3. javac HelloWorldApplet.java
4. http://localhost/test.html
5. appletviewer -classic test.html
-------------------------------------------------------

Reference:

No comments:

Post a Comment