该怎么在MyPanel中调用paintComponent啊
package game;
import javax.swing.*;
import java.awt.*;
public class MyPanel extends JPanel {
public MyPanel(){
this.paintComponent();
}
//重写画组件,参数可以看作画笔
@Override
protected void paintComponent(Graphics g) {
//调用父类方法做一些基本工作
super.paintComponent(g);
this.setBackground(Color.red);
//在画布上添加游戏区域,全部填满
g.fillRect(0,0,1000,600);
}
}
奥会自动调用 把MyPanel里面的内容删除后为什么画板还是黑色的