Guest User

Untitled

a guest
Apr 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class VictoryFrame extends JFrame {
  6. public VictoryFrame(int time) {
  7. this.setTitle("Congratulations!");
  8. this.setSize(300,200);
  9. this.setResizable(false);
  10. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11. Utilities.centerWindow(this);
  12. JPanel victoryPanel = new VictoryPanel(time);
  13. this.add(victoryPanel);
  14. }
  15.  
  16. class VictoryPanel extends JPanel implements ActionListener {
  17. JButton quitButton, highScoresButton, playAgainButton, submit;
  18. JLabel prompt; // prompts user to enter their name
  19. JTextField textField;
  20. HighscoreManager hsm;
  21. int timeMSec;
  22.  
  23. public VictoryPanel(int time) {
  24. timeMSec = time;
  25. prompt = new JLabel("Please enter your name: ");
  26. textField = new JTextField(10);
  27. submit = new JButton("Submit");
  28. quitButton = new JButton("Quit");
  29. highScoresButton = new JButton("High Scores");
  30. playAgainButton = new JButton("Play Again");
  31.  
  32. quitButton.addActionListener(this);
  33. highScoresButton.addActionListener(this);
  34. playAgainButton.addActionListener(this);
  35. submit.addActionListener(this);
  36.  
  37. this.add(prompt);
  38. this.add(textField);
  39. this.add(submit);
  40. this.add(quitButton);
  41. this.add(highScoresButton);
  42. this.add(playAgainButton);
  43. }
  44.  
  45. public void actionPerformed(ActionEvent e) {
  46. Object source = e.getSource();
  47. if(source == quitButton) {
  48. Sounds.FATAL.play();
  49. System.exit(0);
  50. }
  51. else if(source == highScoresButton) {
  52. JFrame highScoreFrame = new HighScoreFrame();
  53. highScoreFrame.setVisible(true);
  54. }
  55. else if(source == playAgainButton) {
  56. JFrame mainFrame = new MainFrame();
  57. mainFrame.setVisible(true);
  58. VictoryFrame.this.dispose();
  59. }
  60. else if(source == submit) {
  61. hsm = new HighscoreManager();
  62. while(true) {
  63. if(textField.getText().isEmpty()) {
  64. // ToDo error message here
  65. }
  66. else {
  67. hsm.updateScoreFile(textField.getText(), timeMSec);
  68. break;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
Add Comment
Please, Sign In to add comment