-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeys.java
68 lines (64 loc) · 1.44 KB
/
Keys.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
// The "Keys" class.
import java.io.*;
public class Keys
{
private int data[];
private String file;
public Keys(String f)
{
data = new int[Consts.KEYSPERCLASS];
try
{
file = f;
FileReader fr = new FileReader (file);
BufferedReader br = new BufferedReader (fr);
int i = 0;
String s = br.readLine();
while( (s != null)&&(i < 5) ) //If there is still data in file, or if enough data was leeched out
{
data[i] = Integer.parseInt(s);
i++;
s = br.readLine();
}
br.close();
}
catch(Exception e){System.out.println("Exception in Keys::Keys(): " + e.toString());};
}
public void setKey(int keyIndex, int changeTo)
{
if( (keyIndex >= 0) && (keyIndex < Consts.KEYSPERCLASS) )
{
data[keyIndex] = changeTo;
}
this.save();
}
public int getKey(int keyIndex)
{
return data[keyIndex];
}
public void save()
{
try
{
FileWriter fw = new FileWriter (file);
PrintWriter pw = new PrintWriter (fw);
for(int i = 0; i < Consts.KEYSPERCLASS; i++)
{
pw.println(data[i]);
}
pw.close();
}
catch(Exception e){System.out.println("Exception in Keys::Save(): " + e.toString());};
}
public int check(int keyCode)
{
for(int i = 0; i < Consts.KEYSPERCLASS; i++)
{
if(data[i] == keyCode)
{
return i;
}
}
return -1;
}
} // Keys class