在Java方法中更改我的背景

在Java方法中更改我的背景,java,colors,background,breakout,Java,Colors,Background,Breakout,我正在用Java编写游戏《突破》。我的背景一开始是灰色的,但当我赢了,我希望它变成绿色。然而,我无法做到这一点。有人能帮我吗 这里宣布了颜色 // Those are the basic statements and properties of the game and prepares the game to start int numberlost =0; Graphics gContext; Image buffer; Thread thread;

我正在用Java编写游戏《突破》。我的背景一开始是灰色的,但当我赢了,我希望它变成绿色。然而,我无法做到这一点。有人能帮我吗

这里宣布了颜色

// Those are the basic statements and properties of the game and prepares the game to start
    int numberlost =0;
    Graphics gContext;
    Image buffer;
    Thread thread;
    boolean leftArrow = false;
    boolean rightArrow = false;
    boolean ballready = true;
    boolean extraball=false;
    Ball ball;
    Field brick;
    Paddle paddle;

    public static final Color 
    PaddleColor=Color.black, 
    ObstacleColor=Color.red, 
    BallColor=Color.red; 
    public static Color FieldColor = new Color(0xcccccc); // background is hexidemal color grey
这是我的win()方法:


此方法仅将
Color.green
颜色指定给
FieldColor
。相反,您应该将其设置为JPanel或用作背景色的任何容器。

因此,它必须如下所示:gContext.setColor(新颜色(0x99FF00));但这仍然不起作用
// This method is called when you win 
        public void win() {
            ball=null;
            paddle=null;
            // the background is set to green
            FieldColor= Color.green;
        }
public void win() {
        ball=null;
        paddle=null;
        // the background is set to green
        FieldColor= Color.green;
}