i have problem with a JPanel in my JInternalFrame. it's like a maze game. after the game finished, i want to display game's statistic in the same panel i draw the tiles of the maze. but instead of displaying the statistic labels. it display nothing. I have to move the JInternalFrame so that the panel display the statistic.
how could that after the game finish (the player reach the key), the panel display the statistic immediately?
Here is the code determining that the game has ended
Expand|Select|Wrap|Line Numbers
- if(level==3)
- {
- //the game is over if level is 3
- JOptionPane.showMessageDialog(null, winnerName+" has completed this Level!");
- gameStart = false;
- playArea.repaint();
- }
Expand|Select|Wrap|Line Numbers
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- if(gameStart)
- gameMap.drawAll(this, g);
- else
- {
- //display game statistic
- if(addedStatistic==false)
- {
- setLayout(new FlowLayout(FlowLayout.CENTER,50, 8));
- add(new JLabel(" MAZE GAME PROGRAMME "));
- //statistic for player1
- if(player1.isHigherScore())
- {
- add(new JLabel("Total score for Player 1 = "+player1.getScore()+" - NEW HIGH SCORE ^^"));
- //update user file with new score
- player1.updateMyScore();
- }
- else
- add(new JLabel("Total score for Player 1 = "+player1.getScore()));
- //statistik for player2
- if(player2.isHigherScore())
- {
- add(new JLabel("Total score for Player 2 = "+player2.getScore()+" - NEW HIGH SCORE ^^"));
- //update user file with new score
- player2.updateMyScore();
- }
- else
- add(new JLabel("Total score for Player 2 = "+player2.getScore()));
- //display winner
- if(player1.getScore() > player2.getScore())
- add(new JLabel("Congratulations Player 1 : "+player1.getName()+" Win this Game."));
- else if(player2.getScore() > player1.getScore())
- add(new JLabel("Congratulations Player 2 : "+player2.getName()+" Win this Game."));
- else
- add(new JLabel("Congratulations You both have the same score"));
- addedStatistic = true;
- repaint();
- }
- }
- }