当前位置: 技术问答>java相关
请问在网页中两个Applet如何互相调用
来源: 互联网 发布时间:2015-01-08
本文导语: 我在网页中加入了两个Applet,现在其中一个Applet想调用另一个Applet中的方法,请问如何实现这一个调用。本人菜鸟,最好能有例子说明,多谢。 | First, you need to make sure you name your applet ...
我在网页中加入了两个Applet,现在其中一个Applet想调用另一个Applet中的方法,请问如何实现这一个调用。本人菜鸟,最好能有例子说明,多谢。
|
First, you need to make sure you name your applet in the APPLET tag using the NAME attribute. The NAME attribute allows other applets on this page to find and communicate with it. For example:
Then, in your other applet, you use the getApplet() method of the AppletContext object:
Applet otherApplet = getAppletContext().getApplet("UserInfo");
What you need to remember is to cast the object returned from getApplet() to the class of object it really is, in order to access any of the applets methods. Just to be safe you could verify that the applet is the class type you expect.
if (otherApplet instanceof UserInfoApplet) {
UserInfoApplet userInfo = (UserInfoApplet) otherApplet;
userInfo.setUserName("Bob");
}
Then, in your other applet, you use the getApplet() method of the AppletContext object:
Applet otherApplet = getAppletContext().getApplet("UserInfo");
What you need to remember is to cast the object returned from getApplet() to the class of object it really is, in order to access any of the applets methods. Just to be safe you could verify that the applet is the class type you expect.
if (otherApplet instanceof UserInfoApplet) {
UserInfoApplet userInfo = (UserInfoApplet) otherApplet;
userInfo.setUserName("Bob");
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。