JPanel setBackground(Color.BLACK) 什麼也做不了
2022-09-05 00:10:55
我有一个自定义的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;
}
}