【问题标题】:Change my background in a method Java在方法 Java 中更改我的背景
【发布时间】:2016-03-22 09:53:56
【问题描述】:

我正在用 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;
        }

【问题讨论】:

    标签: java colors background breakout


    【解决方案1】:
    public void win() {
            ball=null;
            paddle=null;
            // the background is set to green
            FieldColor= Color.green;
    }
    

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

    【讨论】:

    • 那么它必须是这样的: gContext.setColor(new Color(0x99FF00));但这仍然行不通
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 2012-03-12
    • 2011-09-01
    • 2014-04-09
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    相关资源
    最近更新 更多