【发布时间】:2016-11-17 17:58:44
【问题描述】:
我的代码
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 我不同意,原因是不同的。请在下面查看我的答案。
-
@Thomas 我已更正:)
-
@ControlAltDel 不用担心 ;-)