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 96 && ba[i] < 123) ba[i] -= 32; return ba; } private byte[] lower(byte[] ba) { for(int i = 0; i 64 && ba[i] < 91) ba[i] += 32; return ba; } }