我的代码,Eclipse提示有错,但是却能运行,关闭程序效果也有,我是新手,cls类哪里提示有错

import java.awt.*;
import java.awt.event.*;

public class Gridbagframe {
static Frame frame=new Frame("网格布局窗体");
static Button btn1;
static Button btn2;
static Button btn3;

public static void main(String args[]){
frame.setLayout(new GridBagLayout());
GridBagConstraints gbcs=new GridBagConstraints();
btn1=new Button("a");
btn2=new Button("b");
btn3=new Button("c");
gbcs.gridx=0;
gbcs.gridy=0;
gbcs.gridwidth=1;
gbcs.gridheight=1;
frame.add(btn1,gbcs);
frame.add(btn2,gbcs);
gbcs.gridx+=1;
frame.add(btn3,gbcs);
gbcs.gridx+=2;
frame.setVisible(true);
frame.setSize(200,200);
frame.addWindowListener(new cls());
}
}
class cls extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}

第1个回答  2011-10-28
保证是类重名了,你换个类名,或者打个包就好了
第2个回答  2011-10-16
在我这运行没有错。追问

但是确实定义cls那里有个红色叉叉,我写的好几个源程序都在一个项目里

追答

可以把不关联的项目先关了 右击项目 close

追问

WindowAdapter中有几个方法要重写啊?我就一个项目

追答

public void windowClosine(WindowEvent e) {
}

本回答被网友采纳
第3个回答  2011-10-16
没有错啊 ,它是提示你哪一行错了呢 或者什么错误?
相似回答
大家正在搜