javascript与applet通迅的问题? 在嵌入applet时设置其scriptable属性为true,并且指定一个可以引用的名字,就可以在javascript中调用applet的公共方法了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <APPLET CODE="MyApplet" name="myApplet" CODEBASE="classes" HEIGHT="670" WIDTH="1020"> </APPLET>你就可以在script中用myApplet.Method()使用applet的公用方法了 按照上述方法还是不好用,得不到applet属性值。applet的属性和方法都是public 同意juhwali(华仔) 我就是这么用的,可以用的 <object id="MyApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="580" height="420" codebase="/plug-in/j2re-1_3_1_01-win-i.exe#Version=1,3,1,1"> <param name="code" value="MyApplet.class"><param name="type" value="application/x-java-applet;version=1.3"><param name='archive' value='MyApplet.jar'></object>codebase可能要根据你的jre版本修改一下,上面是按照applet打成jar文件的方式做的,code中的值需要带包名之后用document.all.MyApplet.MyProperty试试jettyl(菜鸟一个) 说的<APPLET>标签的方法我没用过,你用document.all.MyApplet.MyProperty先试试看 我也是这么写的为什么不好用<APPLET CODE = "HtmlApplet.NetEcho" WIDTH = "300" HEIGHT = "400" NAME = "NetEcho" scriptable=true> </APPLET><input type="button" value="确 定" onClick="javascript:doApp()"><script language="javascript">function doApp(){ alert(window.document.NetEcho.strOutput);}其中:NetEcho,strOutput 都声明为public </script> 你用这种方式调方法可以吗,如果可以调的到方法,那applet再写个方法,把属性值写在那里面得到,呵呵。 不可以呀,执行javascript时报错!! olivia2046(迷惘的白羊座) :有没有代码发给我 [email protected] 我直接贴这吧,拿原来的东西改了改,只是一个简单的示意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>点击submit键后查看java控制台,看到有输出Applet1,证明调用了applet的方法。应该是好用的,除非你路径什么的没设正确。 我昨天又试了一下,好象在jdk1.3版本上是有问题,会报对象不支持该方法,但我用的jdk1.3.1_02没有问题 根据要求统计单词词频 j2se如何拿到某个请求的cookie 我发现日期的毫秒数是从1970-01-01 08:00:00开始算的,而不是1970-01-01 00:00:00 JScrollPanel 的问题! 英文系统中安装Jbuilder2005和金山词霸有冲突! 一个file类的菜鸟问题 jsp response 问题 散分!领导说让我用j2se 做一个类似校园办公自动化oa的软件平台,不懂? 请各位高手帮忙理解一段代码( 请进) 有没有定位时间的方法? 关于在java中访问网址的问题! 请教一个数据库问题
name="myApplet"
CODEBASE="classes"
HEIGHT="670"
WIDTH="1020">
</APPLET>你就可以在script中用myApplet.Method()使用applet的公用方法了
我就是这么用的,可以用的
width="580" height="420" codebase="/plug-in/j2re-1_3_1_01-win-i.exe#Version=1,3,1,1">
<param name="code" value="MyApplet.class">
<param name="type" value="application/x-java-applet;version=1.3">
<param name='archive' value='MyApplet.jar'></object>codebase可能要根据你的jre版本修改一下,上面是按照applet打成jar文件的方式做的,code中的值需要带包名之后用document.all.MyApplet.MyProperty试试
jettyl(菜鸟一个) 说的<APPLET>标签的方法我没用过,你用document.all.MyApplet.MyProperty先试试看
<APPLET CODE = "HtmlApplet.NetEcho" WIDTH = "300" HEIGHT = "400" NAME = "NetEcho" scriptable=true>
</APPLET>
<input type="button" value="确 定" onClick="javascript:doApp()"><script language="javascript">
function doApp(){
alert(window.document.NetEcho.strOutput);
}其中:NetEcho,strOutput 都声明为public
</script>
//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>
点击submit键后查看java控制台,看到有输出Applet1,证明调用了applet的方法。应该是好用的,除非你路径什么的没设正确。