写韩顺平的坦克大战时面板全变成白色

写完Mypanel类时背景是黑色的

public class MyPanel extends JPanel {
//定义我的坦克
Hero hero=null;
public MyPanel(){
Hero hero =new Hero(100,100);
}

@Override
public void paint(Graphics g) {
    super.paint(g);
    g.fillRect(0,0,1000,750);
    DrawTank(hero.getX(), hero.getY(), g,0,0);

}
public void DrawTank(int x,int y,Graphics g,int direction,int type){
    switch (type){
        case 0:
            g.setColor(Color.cyan);
            break;
        case 1:
            g.setColor(Color.orange);
            break;
    }

//根据方向绘制坦克
switch (direction){
case 0:
g.fill3DRect(x,y,10,60,true);
break;

        default:
            System.out.println("暂不处理");
    }
}

}
写完DrawTank就出现问题了

设置一下背景颜色,使用setbackground方法。