我有以下自定义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;
}
}
setBackground()
。 - trashgodsetOpaque(false)
但仍然希望颜色可见:( - nIcE cOw