【发布时间】:2021-02-01 17:57:57
【问题描述】:
我对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.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 应用程序仍然只有白色背景,但它不应该有红色背景,因为我设置了颜色然后 dispose ?我是否遗漏了问题中的一些代码?
【问题讨论】:
-
1) 为了尽快获得更好的帮助,edit 添加minimal reproducible example 或Short, Self Contained, Correct Example。 2) 现在尝试使用
BufferStrategy还为时过早。首先要精通创建标准 GUI。
标签: java swing colors jframe buffer