我有以下自定义 JPanel,我已经使用 Netbeans GUI 构建器将它添加到我的框架中,但背景不会改变!我可以看到圆圈,用 g.fillOval() 绘制。怎么了?
public class Board extends JPanel{
private Player player;
public Board(){
setOpaque(false);
setBackground(Color.BLACK);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
g.fillOval(player.getxCenter(), player.getyCenter(), player.getRadius(), player.getRadius());
}
public void updatePlayer(Player player){
this.player=player;
}
}