java中关于监听器的使用问题
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class BoxLayoutExa {
/**
* @param args
*/
public static void main(String[] args)
{
new WindowB();
// // TODO Auto-generated method stub
}
}
class WindowB extends Frame
{ Box baseBox,box1,box2;
Color color;
Label label;
WindowB()
{
label=new Label("姓名");
label.setBackground(Color.blue);
color=getBackground();
box1=Box.createVerticalBox();
box1.add(label);
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("email"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("职 业"));
box2=Box.createVerticalBox();
box2.add(new TextField(12));
box2.add(Box.createVerticalStrut(8));
box2.add(new TextField(12));
box2.add(Box.createVerticalStrut(8));
box2.add(new TextField(12));
baseBox=Box.createHorizontalBox();
baseBox.add(box1);
baseBox.add(Box.createHorizontalStrut(15));
baseBox.add(box2);
setLayout(new FlowLayout());
add(baseBox);
setBounds(100,100,200,150);
setVisible(true);
/// this.addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.exit(0);
// }
// });
}
}
上面的程序是一个BoxLayout布局的界面,当我窗口关闭的监听器加上时,提示的是WindowAdapter不能被解析,这个该怎么改,使窗口能关闭?
------解决方案--------------------
import java.awt.event.WindowAdapter;