在WEB中,如何在APPLET中调用另一个APPLET

whyorwhy 2003-03-04 12:03:43
在WEB中,如何在一个APPLET中调用另一个APPLET,而非调用HTML
...全文
61 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
whyorwhy 2003-05-09
  • 打赏
  • 举报
回复
to leejidongdong
还是不太懂,能否给个例子
leejidongdong 2003-05-03
  • 打赏
  • 举报
回复
就是说,可以把Applet当作一个panel来用,这个你会了把?
whyorwhy 2003-03-23
  • 打赏
  • 举报
回复
搞不定,还有何高见?
whyorwhy 2003-03-16
  • 打赏
  • 举报
回复
to shine333
如何ADD?你的意思是增加显示的位置吗?
TO TANGSHANGCHENG
我正在测试,谢谢!!!
tangshancheng 2003-03-15
  • 打赏
  • 举报
回复
一个简单例子

//Applet-同一页面的两applet通信.txt

1、第一个Applet
//: Applet1.java
// Very simple applet
package xjtu.citi;
import java.awt.*;
import java.applet.*;

public class Applet1 extends Applet {
public void paint(Graphics g) {
g.drawString("First applet,What can I do?", 20, 30);
//获得同一页面的applet
Applet2 theOtherApplet =(Applet2)getAppletContext().getApplet("app2");
//使用另一个applet的方法
g.drawString(theOtherApplet.whatidoallforyou(),20,60);

//获得同一页面的所有applet
Enumeration allAppletsOnSamePage = getAppletContext().getApplets();
while(allAppletsOnSamePage.hasMoreElements()) {
Applet appl = (Applet) allAppletsOnSamePage.nextElement();
appl.paint(g); //调用任一个公用方法
}
}
} ///:~

2、第二个Applet
//: Applet2.java
// Easy graphics
package xjtu.citi;
import java.awt.*;
import java.applet.*;

public class Applet2 extends Applet {
public void paint(Graphics g) {
g.drawString("Second applet", 10, 15);
g.draw3DRect(0, 0, 100, 20, false);
}
public String whatidoallforyou(){
return "what I do all for you,zly";
}
} ///:~

3、Html文件:twoapplets.html
<html>
<applet codebase = "." code="xjtu.citi.Applet2" width="400" height="200" name="app2">
</applet>
<br>
<applet codebase = "." code="xjtu.citi.Applet1" width="400" height="200" name="app1">
</applet>
<br>
</html>
shine333 2003-03-15
  • 打赏
  • 举报
回复
把它add到某个地方
applet是个panel
whyorwhy 2003-03-15
  • 打赏
  • 举报
回复
高手呢?
whyorwhy 2003-03-13
  • 打赏
  • 举报
回复
正在测试,谢谢,还有其他方法吗?
whyorwhy 2003-03-13
  • 打赏
  • 举报
回复
to shine333
我用你的方法,但不显示

void jButton1_mousePressed(MouseEvent e)
{
System.out.print("Click");
nihaoApplet ddd=new nihaoApplet();
//jButton1.setText("OK");
ddd.setSize(300,300);
ddd.setVisible(true);
ddd.init();

}
whyorwhy 2003-03-05
  • 打赏
  • 举报
回复
这里是否没有高手
shine333 2003-03-05
  • 打赏
  • 举报
回复
new AnotherApplet().init();
wyl0502 2003-03-05
  • 打赏
  • 举报
回复
在调用者里用new 新建一个被调用的Applet不就行了?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧