-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.java
135 lines (113 loc) · 3.2 KB
/
Options.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
import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
public class Options
{
private JPanel panel;
private JButton reset;
private JButton nextLevel;
private JButton previousLevel;
private JButton open;
private JLabel levelNow;
private JLabel winner1;
private JLabel winner2;
private JTextField level;
private int currentLevel;
private String[] levels;
public Options()
{
//Contructor
levels = new String[40];
currentLevel = 0;
panel = new JPanel();
panel.setLayout(new FlowLayout());
reset = new JButton("Reset Level");
nextLevel = new JButton("Next Level");
previousLevel = new JButton("Previous Level");
open = new JButton("Open Level");
level = new JTextField();
level.setColumns(5);
levelNow = new JLabel();
winner1 = new JLabel();
winner2 = new JLabel();
panel.add(winner1);
panel.add(levelNow);
panel.add(reset);
panel.add(nextLevel);
panel.add(previousLevel);
panel.add(level);
panel.add(open);
panel.add(winner2);
}
public void openFile(String pFileName)
{
//Open file based of parameter, use scanner to read lines out of the file and place them into an array of strings in which one line out of the file is a single element in the array. Close file. If doesnt work throw exception and do nothing
int line = 0;
try {
File fileObject = new File(pFileName);
Scanner reader = new Scanner(fileObject);
while (reader.hasNextLine()){
levels[line] = reader.nextLine();
line++;
}
reader.close();
} catch (FileNotFoundException e){}
}
public JButton getResetButton()
{
return reset;
}
public JButton getOpenButton()
{
return open;
}
public JButton getNextLevelButton()
{
return nextLevel;
}
public JButton getPreviousLevelButton()
{
return previousLevel;
}
public JPanel getPanel()
{
return panel;
}
public void setLevel(int pLevel)
{
//Modulus is used because there is only 40 levels, therefore what ever the user tries to input it will be changed so its valid
currentLevel = pLevel % 40;
if (currentLevel < 0){
currentLevel += 40;
}
}
public String getLevelText()
{
return level.getText();
}
public String getCurrentLevel()
{
return levels[currentLevel];
}
public void updateLevelButton()
{
levelNow.setText("Level " + Integer.toString(currentLevel + 1) );
}
public int getLevel()
{
return currentLevel;
}
public void winner()
{
winner1.setText("WINNER");
winner2.setText("WINNER");
}
public void inTheProcessOfWinning()
{
winner1.setText("");
winner2.setText("");
}
}