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);
}
}
但是确实定义cls那里有个红色叉叉,我写的好几个源程序都在一个项目里
追答可以把不关联的项目先关了 右击项目 close
追问WindowAdapter中有几个方法要重写啊?我就一个项目
追答public void windowClosine(WindowEvent e) {
}