Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class VictoryFrame extends JFrame {
- public VictoryFrame(int time) {
- this.setTitle("Congratulations!");
- this.setSize(300,200);
- this.setResizable(false);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Utilities.centerWindow(this);
- JPanel victoryPanel = new VictoryPanel(time);
- this.add(victoryPanel);
- }
- class VictoryPanel extends JPanel implements ActionListener {
- JButton quitButton, highScoresButton, playAgainButton, submit;
- JLabel prompt; // prompts user to enter their name
- JTextField textField;
- HighscoreManager hsm;
- int timeMSec;
- public VictoryPanel(int time) {
- timeMSec = time;
- prompt = new JLabel("Please enter your name: ");
- textField = new JTextField(10);
- submit = new JButton("Submit");
- quitButton = new JButton("Quit");
- highScoresButton = new JButton("High Scores");
- playAgainButton = new JButton("Play Again");
- quitButton.addActionListener(this);
- highScoresButton.addActionListener(this);
- playAgainButton.addActionListener(this);
- submit.addActionListener(this);
- this.add(prompt);
- this.add(textField);
- this.add(submit);
- this.add(quitButton);
- this.add(highScoresButton);
- this.add(playAgainButton);
- }
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if(source == quitButton) {
- Sounds.FATAL.play();
- System.exit(0);
- }
- else if(source == highScoresButton) {
- JFrame highScoreFrame = new HighScoreFrame();
- highScoreFrame.setVisible(true);
- }
- else if(source == playAgainButton) {
- JFrame mainFrame = new MainFrame();
- mainFrame.setVisible(true);
- VictoryFrame.this.dispose();
- }
- else if(source == submit) {
- hsm = new HighscoreManager();
- while(true) {
- if(textField.getText().isEmpty()) {
- // ToDo error message here
- }
- else {
- hsm.updateScoreFile(textField.getText(), timeMSec);
- break;
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment