summaryrefslogtreecommitdiff
path: root/src/algorithmus/Palisaden.java
blob: fa822d4a9a3e29ef7ed7a576633325caf4393024 (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
package algorithmus;

import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSpinner;

public class Palisaden extends Algorithmus {
	
	private String name;
	private int n;
	
	public Palisaden() {
		name = "Palisaden";
		n = 3;
	}

	@Override
	public void options() {
		JFrame frame = new JFrame();
		frame.setLayout(null);
		frame.setTitle("Palisaden");
		frame.setSize(200, 150);
		JLabel label = new JLabel("Reihen:");
		label.setBounds(5, 30, 100, 20);
		JSpinner spinner = new JSpinner();
		spinner.setBounds(100, 30, 50, 20);
		spinner.setValue(n);
		JButton apply = new JButton("Speichern");
		apply.setBounds(5, 55, 100, 20);
		apply.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				n = (int) spinner.getValue();
			}
		});
		frame.add(label);
		frame.add(spinner);
		frame.add(apply);
		frame.setVisible(true);
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String encode(String input) {
		String out = "";
		int length = input.length();
		String[] rows = new String[n];
		for(int i = 0; i<n; i++)
			rows[i] = "";
		for(int i = 0; i<length; i++) {
			rows[i%n] += input.charAt(i);
		}
		for(int i = 0; i<n; i++)
			out += rows[i] + "\n";
		return out;
	}

	@Override
	public String decode(String input) {
		// TODO Auto-generated method stub
		return null;
	}

}