浏览器上的小程序
如何使用小程序类中声明的一些函数?即
这是我的类
public class hi extends JApplet{
public void HiThere(){
System.out.println("Hi on Java Console");
}
}
,在我的浏览器上它的声明类似于:
<applet.... name="HI" id="HI" ......>Ooops!!!</applet>"
但是当我尝试使用该函数时出现了错误,那么如何使用在我的小程序类上声明的函数?谢谢!!!
How I can use some functions that were declared on the applet class? i.e.
this is my class
public class hi extends JApplet{
public void HiThere(){
System.out.println("Hi on Java Console");
}
}
and on my browser it's declared something like:
<applet.... name="HI" id="HI" ......>Ooops!!!</applet>"
but when I tried to use the function there was a mistake, so how a can use the functions declared on my applet class?? Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您应该对代码进行以下更改:
当您完成此操作后,您的浏览器仍然有错误,请在此处发布确切的错误消息。另外,您可能想查找教程“Java 小程序编程入门”,因为您的代码告诉我,您似乎不知道自己在做什么。
First you should do this change to your code:
When you have done that, and your browser still has an error, then post the exact error message here. Also you might want to look for a tutorial "programming Java applets getting started", since your code tells me, that you don't seem to know what you are doing.
为了从 js 调用类方法,您必须在 html 中声明
我想您想调用
hi.HiThere()
您的问题中定义的方法。然后,您可以在 js 中使用
为了使用最新的 java 版本执行,请记住满足新的 java 安全要求(清单属性 http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html,jar签名... )。
In order to call your class methods from js you must declare the
<object>
in html specifying a.jar
or.class
with your compiled content, the package of the main class and some other parameters like in the follow example (object is for IE, and embed is for FF):I suppose that you want to invoke the
hi.HiThere()
method as defined in your question.Then from the js you can access you object through the
document
using theid
attribute in<object>
orname
in<embed>
in the sample casedocument.hi
. With the follow code you can invoke theHiThere();
method:In order to execute with last java versions remember to meet the new java security requirements (manifest attributes http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html, jar signature... ).
您可以在 JavaScript 中调用 applet 方法:
为此,应从 JavaScript 启动 applet,例如,
在本例中,使用 id= 'mainApplet' 从 JavaScript 启动 applet。在小程序中有我们要调用的appletMethod()方法。为此,您需要调用与具有 id name 的 JavaScript 对象相关的方法。您还可以将参数传递给被调用的方法,如本例所示。
还需要知道从 JavaScript 调用的 applet 方法应该具有特权。为此,您需要将方法代码包装在以下“包装器”中:
此信息取自文章:
Java applet 开发过程中的常见问题
You can call the applet methods in JavaScript:
To do this the applet should be launched from JavaScript, e.g.
In this case the applet is launched from JavaScript with id= 'mainApplet'. In the applet there is appletMethod() method, which we want to call. To do this you need to call the method related to JavaScript object with id name. You can also pass parameters to the called methods, as demonstrated in this example.
Also it is necessary to know that the applet method called from JavaScript should be privileged. To do this you need to wrap the method code in the following "wrapper":
This information is taken from the article:
Frequently Asked Questions during Java applet development