-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.java
185 lines (136 loc) · 5.29 KB
/
Menu.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import sun.audio.*;
import java.io.*;
/** Start-up menu that displays instructions and asks the user how many
* frogs desired */
public class Menu extends JFrame {
////////////////////////////// fields /////////////////////////////////
private JLabel labelInputFrog;
private JTextField inputFrogAmount;
private JButton startButton;
private JLabel rules1;
private JLabel rules2;
//////////////////////////// constructors /////////////////////////////
public Menu() {
createComponents();
setParameters();
}
public Menu(boolean determinant) {
if (determinant) {
createComponents2();
setParameters();
}
}
///////////////////////////// methods ///////////////////////////////
// sets the parameters for the menu JPanel
public void setParameters() {
setSize(600,200);
setResizable(true);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setTitle("Frog Puzzle");
// center JFrame
setLocationRelativeTo(null);
}
// creates the components of the JPanel
public void createComponents() {
/* Window Layout */
/*JLabel*/
labelInputFrog = new JLabel();
labelInputFrog.setText(String.format("Enter number of frogs you wish to be in the puzzle:"));
rules1 = new JLabel();
rules1.setText(String.format("Maneuver the frogs on the right to the left and vice versa."));
rules2 = new JLabel();
rules2.setText(String.format("----------Input must be an integer, 1 to 12----------"));
/*JTextField*/
final int FIELD_WIDTH = 10;
inputFrogAmount = new JTextField(FIELD_WIDTH);
ActionListener actionListener = new ActionListener(){
public void actionPerformed(ActionEvent event){
int numOfFrogs = Integer.parseInt(inputFrogAmount.getText());
if(numOfFrogs <= 12 && numOfFrogs > 0){
new UserInterface(numOfFrogs);
/*------ Background Music ------*/
AudioPlayer MGP = AudioPlayer.player;
AudioStream music;
AudioData MD;
ContinuousAudioDataStream loop = null;
try{
//InputStream test = new FileInputStream("welcome.wav");
//AudioPLayer.player.start(music);
music = new AudioStream(new FileInputStream("welcomeorig.wav"));
MD = music.getData();
loop = new ContinuousAudioDataStream(MD);
}catch(IOException error){System.out.println("File Not Found");}
MGP.start(loop);
/*------------------------------*/
dispose();
} else {
rules2.setText(String.format("THE INPUT MUST BE AN INTEGER, FROM THE NUMBERS 1 TO 12."));
}/*max frogs is 12, must be greater than 0*/
}
};
/*JButton*/
startButton = new JButton("Start Puzzle");
getRootPane().setDefaultButton(startButton);
startButton.addActionListener(actionListener);
/*Panel for the Label, Text-Field, and Button*/
JPanel balancePanel = new JPanel();
balancePanel.add(labelInputFrog);
balancePanel.add(inputFrogAmount);
balancePanel.add(startButton);
JPanel rulesPanel1 = new JPanel();
rulesPanel1.add(rules1);
JPanel rulesPanel2 = new JPanel();
rulesPanel2.add(rules2);
/*Add Panels to Frame*/
add(balancePanel);
add(rulesPanel1);
add(rulesPanel2);
} /*END createComponents() method*/
// creates the components of the JPanel WITHOUT background music
public void createComponents2() {
/* Window Layout */
/*JLabel*/
labelInputFrog = new JLabel();
labelInputFrog.setText(String.format("Enter number of frogs you wish to be in the puzzle:"));
rules1 = new JLabel();
rules1.setText(String.format("Maneuver the frogs on the right to the left and vice versa."));
rules2 = new JLabel();
rules2.setText(String.format("----------Input must be an integer, 1 to 12----------"));
/*JTextField*/
final int FIELD_WIDTH = 10;
inputFrogAmount = new JTextField(FIELD_WIDTH);
ActionListener actionListener = new ActionListener(){
public void actionPerformed(ActionEvent event){
int numOfFrogs = Integer.parseInt(inputFrogAmount.getText());
if(numOfFrogs <= 12 && numOfFrogs > 0){
new UserInterface(numOfFrogs);
dispose();
} else {
rules2.setText(String.format("THE INPUT MUST BE AN INTEGER, FROM THE NUMBERS 1 TO 12."));
}/*max frogs is 12, must be greater than 0*/
}
};
/*JButton*/
startButton = new JButton("Start Puzzle");
getRootPane().setDefaultButton(startButton);
startButton.addActionListener(actionListener);
/*Panel for the Label, Text-Field, and Button*/
JPanel balancePanel = new JPanel();
balancePanel.add(labelInputFrog);
balancePanel.add(inputFrogAmount);
balancePanel.add(startButton);
JPanel rulesPanel1 = new JPanel();
rulesPanel1.add(rules1);
JPanel rulesPanel2 = new JPanel();
rulesPanel2.add(rules2);
/*Add Panels to Frame*/
add(balancePanel);
add(rulesPanel1);
add(rulesPanel2);
}
}/*END Menu CLASS*/