/
WonWindow.java
140 lines (106 loc) · 4.09 KB
/
WonWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit;
import java.net.URL;
public class WonWindow extends JPanel
{
private JLabel infoLabel; //declares a label
private JLabel achievementLabel; //declares a label
private JPanel achievementPanel; // declares a panel
private JLabel skillLabel; //declares a label
private JPanel skillpointPanel; // declares a panel
// private JLabel buttonLabel; //declares a label
private JPanel buttonPanel; // declares a panel
private JButton replayButton;
private JButton quitButton; // QUIT BUTTON buttonLabel
//
// Constructor
//
public WonWindow()
{
// set this panel to a grid layout and change its color
setLayout(new GridLayout(3,1,0,5));
setBackground(Color.white);
// initialize 3 panels, set their colors and add them to the main panel
//
// First Panel
//
setLayout(new GridLayout(0,1,0,70));
setBackground(Color.black);
infoLabel = new JLabel("<html><div style=\"textalign: center;\">"+"You've Won!"+"</html>"); //instantiates new JLabel
infoLabel.setFont(new Font("Times New Roman", Font.PLAIN, 30));
infoLabel.setForeground(Color.WHITE);
add(infoLabel); //adds this new JLabel
//
// Achievement Panel
//
achievementPanel = new JPanel();
achievementPanel.setBackground(Color.white);
add(achievementPanel);
achievementLabel = new JLabel("Achievements:");
//achievementLabel.setText("<html><div style=\"textalign: center;\">"+"Achievements:"+"</html>");
achievementLabel.setFont(new Font("Times New Roman", Font.PLAIN, 20));
achievementLabel.setForeground(Color.black);
achievementPanel.add(achievementLabel);
//
// Skills Panel
//
skillpointPanel = new JPanel();
skillpointPanel.setBackground(Color.white);
add(skillpointPanel);
skillLabel = new JLabel("Skills Points:");
//skilLabel.setText("<html><div style=\"textalign: center;\">"+"Skills"+"</html>");
skillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 20));
skillLabel.setForeground(Color.black);
skillpointPanel.add(skillLabel);
//
// Button Panel
//
buttonPanel = new JPanel();
buttonPanel.setBackground(Color.black);
add(buttonPanel);
/*
buttonLabel = new JLabel("");
buttonLabel.setFont(new Font("Times New Roman", Font.PLAIN, 20));
buttonLabel.setForeground(Color.WHITE);
buttonPanel.add(buttonLabel);
*/
// Buttons
//quit
quitButton = new JButton("QUIT"); // quits game
quitButton.addActionListener(new ButtonListener());
buttonPanel.add(quitButton);
//replay
replayButton = new JButton("RESTART");// closes current window and starts a new game from the instructions window
replayButton.addActionListener(new ButtonListener());
buttonPanel.add(replayButton);
//
}
/**
* ButtonListener is a private class for responding to button push events
*/
private class ButtonListener implements ActionListener {
/** quits the game if quit button is pushed, changes the text of the buttons
**/
public void actionPerformed (ActionEvent event)
{
//quit button was pressed
if (event.getSource() == quitButton) System.exit(0);
}
}
public static void main(String [] args){
JFrame frame = new JFrame ("Wah, wah, waaaahh....");
// creates a new frame
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // makes a functional exit operation
JPanel pane = new JPanel(new GridBagLayout());
pane.setBackground(Color.black);
// adding the tabs which have panels to the tabbed panel
pane.add (new WonWindow());
frame.getContentPane().add(pane); // adding the pane to the frame
frame.pack(); // unpacking what we need
frame.setSize(950,650); //sets the size after unpacking
frame.setResizable(false); //frame can no longer can be resized
frame.setVisible(true); // make the frame/everything? visible
}
}