blob: 06e35d6c032609e92b71f4b65472b96d5fb629f7 (
plain)
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
|
package algorithmus;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.UnsupportedEncodingException;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Case extends Algorithmus {
private String name = "Case";
private boolean low = true;
public String getName() {
return name;
}
public void options() {
JFrame frame = new JFrame();
frame.setLayout(null);
frame.setTitle("Case");
frame.setSize(100, 100);
frame.setResizable(false);
Checkbox cb = new Checkbox("To Lowercase");
cb.setBounds(5, 5, 100, 20);
JButton apply = new JButton("Apply");
apply.setBounds(5, 30, 75, 20);
apply.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
low = cb.getState();
}
});
frame.add(cb);
frame.add(apply);
frame.setVisible(true);
}
public String encode(String input) {
try {
if(low)
return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
else
return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "Error";
}
}
public String decode(String input) {
try {
if(low)
return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
else
return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "Error";
}
}
private byte[] upper(byte[] ba) {
for(int i = 0; i<ba.length; i++)
if(ba[i] > 96 && ba[i] < 123)
ba[i] -= 32;
return ba;
}
private byte[] lower(byte[] ba) {
for(int i = 0; i<ba.length; i++)
if(ba[i] > 64 && ba[i] < 91)
ba[i] += 32;
return ba;
}
}
|