java的非法表达式开始 新人求解。。。 找了半天没找出错哪啦?
发布网友
发布时间:2024-10-11 05:27
我来回答
共3个回答
热心网友
时间:2024-11-14 07:10
f.addWindowListener(new WindowAdapter());{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
} ;
你这一段是要干什么?你是要加一个监听器,监听器方法要用内部类来实现吧?给你改成这样了,你看看是不是,
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();
}
热心网友
时间:2024-11-14 07:11
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
热心网友
时间:2024-11-14 07:13
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();
}
}
//匿名内部类是这样的
/*
f.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent evt){System.exit(0); }
}
);
*/