我正在尝试将屏幕的背景颜色设置为绿色。
到目前为止我的代码:
package game;
import java.awt.*;
import javax.swing.JFrame;
public class Game extends JFrame {
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
Game g = new Game();
g.run(dm);
}
public void run(DisplayMode dm) {
setBackground(Color.GREEN);
setForeground(Color.WHITE);
setFont(new Font("arial", Font.PLAIN, 24));
Screen s = new Screen();
try {
s.setFullScreen(dm, this);
try {
Thread.sleep(5000);
} catch (Exception E) {
}
} finally {
s.restoreScreen();
}
}
@Override
public void paint(Graphics g){
g.drawString("Check Screen", 200, 200);
}
}
当我运行程序时,我得到了这个:
屏幕应该是绿色的线:
setBackground(Color.GREEN);
为什么我运行程序时背景没有设置为绿色?