package second; import java.awt.Color; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.*; public class Window extends Frame { public Window(String string){ super(string);//调用父类构造方法 } public static void main(String[] args){ Window w = new Window("我的第一个window!!");//实例化 w.setSize(500,300);//设置窗口大小 w.setBackground(Color.blue);//背景颜色 w.setTitle("哈哈,我才是第一个!");//标题 w.setLayout(null);//取消布局管理器 w.setVisible(true);//显示 w.addWindowListener(w.new writeWindow());//添加窗口监视器 } class writeWindow extends WindowAdapter { public void windowClosing(WindowEvent e){//监视关闭 System.exit(0); } } }