//希望能有用
//纠正一下,html代码应写为:
<HTML>
<HEAD>
<TITLE>Example Javascript/Applet</TITLE>
<SCRIPT language="javascript">
<!--
function execute() {
result = myapp.myMethod();
alert ("Method myMethod returned: "+result);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT type="BUTTON" value="Execute Method" onclick="execute()">
</FORM>
<APPLET code="MyApp.class" width="100" height="100" name="myapp">
</BODY>
</HTML>
//这是测试程序
import java.awt.*;
import java.applet.*;public class MyApp extends Applet{
Graphics g;
public void init(){
g = getGraphics();
}
public void myMethod(){
g.drawString("Hello World", 20, 20);
}
}
//纠正一下,html代码应写为:
<HTML>
<HEAD>
<TITLE>Example Javascript/Applet</TITLE>
<SCRIPT language="javascript">
<!--
function execute() {
result = myapp.myMethod();
alert ("Method myMethod returned: "+result);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT type="BUTTON" value="Execute Method" onclick="execute()">
</FORM>
<APPLET code="MyApp.class" width="100" height="100" name="myapp">
</BODY>
</HTML>
//这是测试程序
import java.awt.*;
import java.applet.*;public class MyApp extends Applet{
Graphics g;
public void init(){
g = getGraphics();
}
public void myMethod(){
g.drawString("Hello World", 20, 20);
}
}
lym2000肯定是知道这样作的。你可以请教他!】
import java.applet.*;
import java.net.*;public class inJava extends Applet{
public void init(){
String msg="We will jump to an HTML tag!";
try {
getAppletContext().showDocument
(new URL("javascript:doAlert(\""+msg+"\")"));
//getAppletContext().showDocument
//(new URL("javascript:jumpTo(\"#JUMP\")"));
}
catch (MalformedURLException me) { }
}
}
//file inJava.html<HTML><HEAD></HEAD><BODY><!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<OBJECT classid="clsid:E19F9330-3110-11d4-991C-005004D3B3DB"
WIDTH = 400 HEIGHT = 400 NAME = "myApplet" codebase="http://java.sun.com/products/plugin/1.3.0_01/jinstall-130_01-win32.cab#Version=1,3,0,1">
<PARAM NAME = CODE VALUE = "inJava.class" >
<PARAM NAME = NAME VALUE = "myApplet" >
<PARAM NAME = MAYSCRIPT VALUE = true ><PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.3.0_01">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;jpi-version=1.3.0_01" CODE = "inJava.class" NAME = "myApplet" WIDTH = 400 HEIGHT = 400 MAYSCRIPT = true scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3.0_01/plugin-install.html"><NOEMBED></NOEMBED>
</EMBED>
</COMMENT>
</OBJECT><!--
<APPLET CODE = "inJava.class" WIDTH = 400 HEIGHT = 400 NAME = "myApplet" MAYSCRIPT = true>
</APPLET>
-->
<!--"END_CONVERTED_APPLET"--><P>
<P>
<A NAME="JUMP">jump here from Java via Javascript</A>
<SCRIPT language="JavaScript">
function doAlert(s) {
alert(s);
}
function jumpTo(tag) {
self.location=tag;
}
</SCRIPT>
</BODY>
</HTML>其中后面的html文件是用htmlconv1_3_0_01.jar文件由下面文件转换的。
<HTML><HEAD></HEAD><BODY><APPLET CODE="inJava.class"
NAME="myApplet" MAYSCRIPT
HEIGHT=400 WIDTH=400>
</APPLET>
<P>
<a href="javascript:doAlert(\"+"hello!"+"\")">hello!</a>
<P>
<A NAME="JUMP">jump here from Java via Javascript</A>
<SCRIPT language="JavaScript">
function doAlert(s) {
alert(s);
}
function jumpTo(tag) {
self.location=tag;
}
</SCRIPT>
</BODY>
</HTML>
http://java.sun.com/j2se/1.3/jre/download-windows.html下载安装后我的例子即可运行了祝你成功!
他的示例我运行很好。