用 java编写的图形用户界面运行后怎么关不掉

来源:百度知道 编辑:UC知道 时间:2024/06/07 16:13:50
import java.awt.*;
import javax.swing.*;
public class GUIDemo {

public static void main(String[] args) {

Frame f=new Frame("候选人输入");

Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();

Label l1=new Label("第一候选人");
Label l2=new Label("第一候选人");
Label l3=new Label("第一候选人");

TextField t1=new TextField(30);
TextField t2=new TextField(30);
TextField t3=new TextField(30);

Button b1=new Button("输入");
Button b2=new Button("输入");
Button b3=new Button("输入");

f.setLayout(new GridLayout(4,1));
p1.setLayout(new FlowLayout());
p2.setLayout(new FlowLayout());
p3.setLayout(new FlowLayout());

p1.add(l1);
p1.add(t1);
p1.add(b1);
p1.setBackground(Color.yellow);

加上这段代码,为其添加关闭窗口事件的监听器
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
// f.setVisible(false);
System.exit(0);
}

});
当然别忘了引入java.awt.event.*包

呵呵,还没看到Java的事件处理吧
加上下面的代码看看
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});

你没有关闭的东西 怎么关闭的了呢??
.