在方法Java中更改我的背景

时间:2016-03-22 09:53:57

标签: java colors background breakout

我正在使用Java编写游戏Breakout。我的背景一开始是灰色的,但是当我赢了,我希望它变成绿色。但是,我无法实现这一目标。有人可以帮帮我吗?

这里声明了颜色;

// 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()方法:

// This method is called when you win 
        public void win() {
            ball=null;
            paddle=null;
            // the background is set to green
            FieldColor= Color.green;
        }

1 个答案:

答案 0 :(得分:1)

public void win() {
        ball=null;
        paddle=null;
        // the background is set to green
        FieldColor= Color.green;
}

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