java - JFrame background color not working -


my code

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);         }  } 

why isn't frame.getcontentpane().setbackground(color.yellow); working?

i've tried rearrange order, setting color after making frame visible.

it works alright, cannot see background color because flappybird instance drawn on top of it. can verify replacing game class empty canvas so:

public static void main(string[] args) throws interruptedexception {     jframe frame = new jframe("flappy bird");     frame.setsize(1200, 800);     //flappybird game = new flappybird();     canvas game = new canvas();     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);     // } } 

there 2 things can try:

  1. setting background color not of frame's content pane of game:
//frame.getcontentpane().setbackground(color.yellow); game.setbackground(color.yellow); 
  1. making sure frame's background color shows through game instance making latter transparent:
game.setopaque(false); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -