This Program contains step by step details from developing an applet to deploying
into server.
It describes how
to invoke an applet in JSP page.
A Java applet is a
special kind of Java program that a browser enabled with Java
technology can download from the internet and run. Applets are used
to make the web site more dynamic than html pages.
JSP Page Code snippet
<html>
<head>
<title>Using the Java Plugin</title>
</head>
<body>
<h4>Applet running in the plugin</h4>
<jsp:plugin type="applet" code="TimeApplet" codebase="." archive="JspApplet.jar"
width="500"
height="500"
jreversion="1.7">
<jsp:params>
<jsp:param name="font" value="SansSerif" />
<jsp:param name="fsize" value="12" />
<jsp:param name="image" value="Menu.gif"/>
</jsp:params>
<jsp:fallback>
<B>Unable to start plugin!</B>
</jsp:fallback>
</jsp:plugin>
</body>
</html>
-------------
TimeApplet snippet
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Date;
public class TimeApplet extends Applet implements Runnable {
Thread timerThread;
/* Applet Lifestyle Methods */
public void start() {
timerThread = new Thread(this, "Clock");
timerThread.start();
}
public void stop() {
if (timerThread == null)
return;
timerThread.stop();
timerThread = null;
}
/* Runnable interface method */
public void run() {
while (timerThread != null) {
repaint(); // request a redraw
try {
timerThread.sleep(1000);
} catch (InterruptedException e){ /* do nothing*/ }
}
}
/* AWT method */
public void paint(Graphics g) {
Date d = new Date();
g.drawString(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds(), 1, 10);
}
}