1

I am programming the game Breakout in Java. My background is grey at first, but when I win I want it to change to green. However, I cannot manage to achieve this. Can somebody help me?

Here the colors are declared;

// 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

and this is my win() method:

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

1 Answers1

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

This method just assigns Color.green color to the FieldColor. Instead, you should set it to JPanel or whichever container you are using as a background color.

Vitthal Kavitake
  • 879
  • 5
  • 18
  • So then it would have to be like this: gContext.setColor(new Color(0x99FF00)); But that still doesn't work – Maris Mar 22 '16 at 10:07