I'm trying to put a label over the top of my game that shows the score but whenever I do it, the label appears on a blank grey screen and the game isn't visible. I'll attach the code and the area I'm trying to insert the JLabel. (I know the code is poorly written but I'm still learning. Any tips and tricks would be good)
public static void main(String[] args) throws InterruptedException {
int timer = 0;
int Time = 0;
JFrame frame = new JFrame("Grid Hopper");
frame.setSize(1120,800);
frame.setResizable(false);
frame.setVisible(true);
frame.setTitle("Grid Hopper");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridHopper game = new GridHopper();
game.setBackground(Color.gray);
frame.add(game);
JLabel score = new JLabel();
score.setText("Score to be calculated");
frame.add(score);
//ACTUAL GAME-RUN WHILE LOOP!
while(game.dead != true){
game.repaint();
//game.moveBall(); NOW USED FOR PLAYER MOVEMENT
if (Time > 3){
game.moveBall5();
}
if (Time > 10){
game.moveBall4();
}
if (Time > 30){
game.moveBall2();
}
if (Time > 60){
game.moveBall3();
}
game.collision();
Thread.sleep(2);
timer++;
if (timer%500 == 0){
Time++;
System.out.println(Time);
}
}
}