我的代码JFrame的背景颜色不工作
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Flappy bird");
frame.setSize(1200, 800);
FlappyBird game = new FlappyBird();
frame.getContentPane().setBackground(Color.YELLOW);
frame.add(game);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
while (true) {
game.moveBall();
game.gameOver();
game.moveRect();
game.repaint();
Thread.sleep(14);
}
}
为什么不frame.getContentPane().setBackground(Color.YELLOW);
工作?
我试图重新排列顺序,像制作框架可见后设置的颜色。
我投票,因为这个问题是为什么Java核心的组成部分在它的方式被实现,而不是一些其他的方式来关闭这一问题作为题外话。这是个什么 – ControlAltDel
@ControlAltDel我不同意,原因是不同的。请检查我的答案。 – Thomas
@Thomas我站在更正:) – ControlAltDel