public class PanelGame extends JPanel{ private Lay[] lays=null; public PanelGame(){ lays=new Lay[]{ //硬编码,是非常不好的开发习惯 //我们要尽量将数字或字符串定义成常量,或者写入配置文件 new Lay(40,32,334,279), new Lay(40,343,334,279), new Lay(414,32,334,590), new Lay(788,32,334,124), new Lay(788,188,176,148), new Lay(964,188,158,148), new Lay(788,368,334,200) }; } @Override//表示下面的方法要覆盖父类的方法 public void paintComponent(Graphics g){ //循环刷新游戏画面 for(int i=0;i<lays.length;i++){ //刷新层窗口 lays[i].creatWindow(g); } } }