From c9dd9469183d95c6c2f4d01e3d6365ec57386a65 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:43:46 +0200 Subject: Initial commit --- src/algorithmus/Case.java | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 src/algorithmus/Case.java (limited to 'src/algorithmus/Case.java') diff --git a/src/algorithmus/Case.java b/src/algorithmus/Case.java new file mode 100755 index 0000000..06e35d6 --- /dev/null +++ b/src/algorithmus/Case.java @@ -0,0 +1,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 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; + } + +} -- cgit v1.2.1