這個程式為什麼沒有執行結果??散分來者有分

alf7927 2002-07-23 07:00:51
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
<APPLET
CODE=border.class
WIDTH=200
HEIGHT=200 >
</APPLER>
*/
class textPanel extends Panel
{
TextField Text1;
textPanel(){
Text1=new TextField(30);
add(Text1);
}
}

public class border extends Applet implements ActionListener
{
Button button1,button2,button3,button4;
textPanel Panel1;
public void init()

{
setLayout(new BorderLayout());

button1=new Button("1");
add("North",button1);
button1.addActionListener(this);

button2=new Button("2");
add("West",button2);
button2.addActionListener(this);

button3=new Button("3");
add("South",button3);
button3.addActionListener(this);

button4=new Button("4");
add("East",button4);
button2.addActionListener(this);

Panel1=new textPanel();
add("Center", Panel1);
Panel1.Text1.setLocation(0,0);
}

public void actionPerformed(ActionEvent e)
{
Panel1.Text1.setText("Button"+((Button) e.getSource()).getLabel()+"clicked.");
}
}

這個程式為什麼沒有執行紹果啊,請高人指教.
...全文
32 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
earthharp 2002-07-29
  • 打赏
  • 举报
回复
up
alf7927 2002-07-24
  • 打赏
  • 举报
回复
你們都說的不對,用上面的方法依然沒有結果的
newman78 2002-07-24
  • 打赏
  • 举报
回复
up,不是騙分,呵呵
newman78 2002-07-24
  • 打赏
  • 举报
回复
<APPLET
CODE=border.class
WIDTH=200
HEIGHT=200 >
</APPLER> <----*

呵呵,您寫的都很對,就是有個地方打了個別字,是</APPLET>哦,再try吧
mygarfield 2002-07-23
  • 打赏
  • 举报
回复
要不你可以自己编写一个main程序,在该程序里调用init()。
earthharp 2002-07-23
  • 打赏
  • 举报
回复
up
liuhai_2599 2002-07-23
  • 打赏
  • 举报
回复
天王盖地虎老兄的发言让我又学了一招﹐多谢﹗
MrYoucheng 2002-07-23
  • 打赏
  • 举报
回复
<HTML>
<APPLET>
CODE=border.class
WIDTH=200
HEIGHT=200 >
</APPLET>
</HTML>
_No1_ 2002-07-23
  • 打赏
  • 举报
回复
改成application也能运行。
下面代码只是添加了main()函数。其他没动。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/*
<APPLET
CODE=border.class
WIDTH=200
HEIGHT=200 >
</APPLER>
*/

class textPanel extends Panel {
TextField Text1;
textPanel(){
Text1=new TextField(30);
add(Text1);
}
}

public class border extends Applet implements ActionListener{
Button button1,button2,button3,button4;
textPanel Panel1;

public void init(){
setLayout(new BorderLayout());


button1=new Button("1");
add("North",button1);
button1.addActionListener(this);

button2=new Button("2");
add("West",button2);
button2.addActionListener(this);

button3=new Button("3");
add("South",button3);
button3.addActionListener(this);

button4=new Button("4");
add("East",button4);
button2.addActionListener(this);

Panel1=new textPanel();
add("Center", Panel1);
Panel1.Text1.setLocation(0,0);
}

public void actionPerformed(ActionEvent e){
//Panel1.Text1.setText("Button"+((Button) e.getSource()).getLabel()+"clicked.");
Object source = e.getSource();
if (source == button4){
this.destroy();
}
}

public static void main(String args[]) {
border b = new border();
b.init();
b.start();

Frame f = new Frame("Border");

f.add("Center", b);
f.setSize(300, 300);
f.show();
}

}

_No1_ 2002-07-23
  • 打赏
  • 举报
回复
你的程序在网页里可以看到,但是用appletviewer确实不行,奇怪
qiyao 2002-07-23
  • 打赏
  • 举报
回复
最好html文件与class文件在同一文件夹中
你的程序没有问题,只是找不到*.class
好运与你同行。。。
qiyao 2002-07-23
  • 打赏
  • 举报
回复
html file and class file at the same path,
好运与你同行。。。
alf7927 2002-07-23
  • 打赏
  • 举报
回复
為什麼有的程式可以用appletviewer XX.java 看到結果呢??
trilel 2002-07-23
  • 打赏
  • 举报
回复
of course 不可以,应该是
appletviewer xx.htm(html)
xx.class 嵌在htm中,象上面两层楼那位老兄写的。。
alf7927 2002-07-23
  • 打赏
  • 举报
回复
用appleviewer XX.java也不可以
llsoft 2002-07-23
  • 打赏
  • 举报
回复
applet程序是嵌在网页中运行的。用法如上
BugHunterPro 2002-07-23
  • 打赏
  • 举报
回复
编译成class后
你需要一个html文件包含下面代码:

<APPLET
CODE=border.class
WIDTH=200
HEIGHT=200 >
</APPLER>
浏览这个html

62,629

社区成员

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

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