import javax.swing.*;
import java.awt.*;
public class Window extends JFrame{
public void lanchFrame(){
this.setVisible(true); //设置窗口是可见的
this.setTitle("植物大战僵尸");//设置标题
Container con = this.getContentPane();
con.setBackground(Color.cyan);//给窗口上色,必须在内容面板设置
this.setSize(868, 600); //设置窗口的大小
this.setLocationRelativeTo(null); //设置窗口的位置为最中央
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口可关闭,否则即使点”ד,该窗口仍在运行
}
}
public class Text {
public static void main(String[] args) {
Window window = new Window();
window.lanchFrame();
}
}
结果如下: