3、定义MyPanel类

class MyPanel extends JPanel{
     MyTank mt;
     EnemyTank et;
     ArrayList<EnemyTank> ets=new ArrayList<EnemyTank>();
     int etnum=5;
     public void paint(Graphics g){
        super.paint(g);
        g.fill3DRect(0, 0, 700, 700, false);
         for(int i=0;i<ets.size();i++){
            et=ets.get(i);
            et.paintTank(g);
        }
        mt.paintTank(g);
    }
    public MyPanel(){
        mt=new MyTank(300,600);
        for(int i=0;i<etnum;i++){
            et=new EnemyTank(100*(i+1),100);
            ets.add(et);
        }
    }
}
posted @ 2019-11-01 18:42  -筱  阅读(605)  评论(0)    收藏  举报