import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class WelcomeApplet extends Applet implements ActionListener {
Label lblName;
TextField txtName;
TextField txtDisp;
public void init() {
lblName = new Label("请您输入您的名字");
txtName = new TextField(8);
txtDisp = new TextField(20);
add(lblName);
add(txtName);
add(txtDisp);
txtName.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
txtDisp.setText(txtName.getText() + "欢迎你来到java世界");
}
public static void main(String args[]) {
Frame f = new Frame("欢迎");
f.addWindowListener(new WindowAdapter() {
public void widowClosing(WindowEvent evt) {
System.exit(0);
}
});
WelcomeApplet a = new WelcomeApplet();
a.init();
f.add("Center", a);
f.setSize(400, 300);
f.show();
a.start();
}
}
1、注意大小写
2、缺少括号}
3、steSize改成setSize
4、shouw改成show
你的程序主要问题是打字打错了,没什么别的问题,我给你改完了。你看看吧。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class WelcomeApplet extends Applet implements ActionListener{
Label lblName;
TextField txtName;
TextField txtDisp;
public void init(){
lblName=new Label("请您输入您的名字");
txtName=new TextField(8);
txtDisp=new TextField(20);
add(lblName);
add(txtName);
add(txtDisp);
txtName.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
txtDisp.setText(txtName.getText()+"欢迎你来到java世界");
}
public static void main(String args[]){
Frame f=new Frame("欢迎");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
WelcomeApplet a=new WelcomeApplet();
a.init();
f.add("Center",a);
f.setSize(400,300);
f.show();
a.start();
}
}
你的addWindowListener函数写错了。
Frame f=new Frame("欢迎");
f.addWindowListener(new WindowAdapter());
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
}
;
应该改成
Frame f=new Frame("欢迎");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
注意大小括号的对应。
一楼正解
楼上正解、