applet文件:Applet1.java
//public String getAppletInfo()是javascript中将要调用的方法,编译的时候记得带包
package manager_test;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class Applet1 extends JApplet {
boolean isStandalone = false;
String var0;
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public Applet1() {
}
/**Initialize the applet*/
public void init() {
try {
var0 = this.getParameter("param0", "");
}
catch(Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
}
/**Get Applet information*/
public String getAppletInfo() {
System.out.println ("Applet1");
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
String[][] pinfo =
{
{"param0", "String", ""},
};
return pinfo;
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}
jsp文件Applet1.jsp
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<SCRIPT language=JavaScript>
function PutOut()
{
window.document.MyApplet.getAppletInfo();
}
</SCRIPT>
<body bgcolor="#FFFFFF">
<table width="90%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td colspan="4">
<object id="MyApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="580" height="420" name="applet"
codebase="/plug-in/j2re-1_3_1_01-win-i.exe#Version=1,3,1,1">
<param name="code" value="manager_test.Applet1.class">
<param name="type" value="application/x-java-applet;version=1.3">
<!--<param name='archive' value='SystemStateapplet.jar'>-->
</object></td>
</tr>
</table>
<p> </p>
<p>
<input type="submit" name="Submit" value="Submit" onClick=PutOut()>
</p>
</body>
</html>
JavaScript 与applet信息交互
最新推荐文章于 2016-02-14 16:33:00 发布