Java 程序不更新背景色
我对java很陌生,如果这是一个愚蠢的问题,我很抱歉。下面是我的代码Java 程序不更新背景色,java,swing,colors,jframe,buffer,Java,Swing,Colors,Jframe,Buffer,我对java很陌生,如果这是一个愚蠢的问题,我很抱歉。下面是我的代码 private void draw(){ //this is where the background is going to be made //paddles gonna be made here as well plus the score and the ball //will dispose here BufferStrategy Buffer = this.getBufferStr
private void draw(){
//this is where the background is going to be made
//paddles gonna be made here as well plus the score and the ball
//will dispose here
BufferStrategy Buffer = this.getBufferStrategy();
if(Buffer==null){
this.createBufferStrategy(3);
return;
}
Graphics graphics = Buffer.getDrawGraphics();
//drawing the background
drawbg(graphics);
//disposing everything. disposing means to actually show on the screen
graphics.dispose();
Buffer.show();
}
private void drawbg(Graphics graphics){
//black bg
graphics.setColor(Color.red);
graphics.fillRect(0,0,W,H); //fills the whole screen
当我运行这段代码时,我的Jframe应用程序仍然只有白色背景,但它不应该有红色背景,因为我设置了颜色,然后进行了处理?我是不是在问题中遗漏了一些代码?我认为应该是
Color.RED
。全副武装。我不能评论,因为它不让我评论,但请尝试一下。确保你的坐标确实填满了整个屏幕,我知道JFrame和JPanel有时会对这种东西感到奇怪。“我知道JFrame和JPanel有时会对这种东西感到奇怪。”这句话暗示了为什么你不能给出答案。不要试图玩弄这个系统。“至少试着帮助那个人”我为OP添加了一个&添加了一个,以引起人们对最有能力帮助的人的注意。仍在等待他们对建议采取行动。。如果问问题的人忽略了建议,他们就不太可能得到帮助。1)为了更快得到更好的帮助,可以添加一个或。2) 现在尝试使用缓冲策略还为时过早。首先要精通创建标准GUI。