import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.datatransfer.*;
public class Interface extends JApplet
{
JTextField eingabe,schluesselfeld,ausgabe;
JButton entschluesseln,verschluesseln,ok,leeren,kopieren;
JLabel oben,mitte,unten,textlabel,textlabel1,textlabel2;
JFrame fenster;
JDialog dialog;
JDialog popup = dialog;
String input;
String schluessel;
String[] buttons = {"Neuen Text kopieren","OK","Textfelder leeren"};
public void dialog_create() {
JDialog dialog = new JDialog();
dialog.setLayout(null);
dialog.setTitle("Information");
dialog.add(textlabel = new JLabel("Eingegegebener Text: "+input));
dialog.add(textlabel1 = new JLabel("Schlüssel: "+schluessel));
dialog.add(textlabel2 = new JLabel("Neuer Text:"+ausgabe.getText()));
dialog.add(ok = new JButton("OK"));
dialog.add(kopieren = new JButton("Neuen Text kopieren"));
dialog.add(leeren = new JButton("Textfelder leeren"));
ok.addActionListener(new OkAction());
kopieren.addActionListener(new KopierenAction());
leeren.addActionListener(new LeerenAction());
textlabel.setBounds(25,25,200,25);
textlabel1.setBounds(25,60,200,25);
textlabel2.setBounds(25,95,200,25);
dialog.setSize(420,220);
dialog.setVisible(true);
ok.setBounds(25,140,50,25);
kopieren.setBounds(85,140,160,25);
leeren.setBounds(260,140,150,25);
textlabel.setBounds(25,25,250,25);
}
public void button_create() {
fenster.setLayout(null);
verschluesseln = new JButton("verschlüsseln");
entschluesseln = new JButton("entschlüsseln");
entschluesseln.setBounds(140,220,115,25);
verschluesseln.setBounds(23,220,115,25);
Listener_entschluesseln Encoding = new Listener_entschluesseln();
Listener_verschluesseln Decoding = new Listener_verschluesseln();
entschluesseln.addActionListener(Encoding);
verschluesseln.addActionListener(Decoding);
fenster.add(entschluesseln);
fenster.add(verschluesseln);
}
private void textfield_create()
{
fenster.setLayout(null);
eingabe = new JTextField("");
schluesselfeld = new JTextField("");
ausgabe = new JTextField("");
eingabe.setBounds(25, 25, 230, 50);
schluesselfeld.setBounds(25,90,230,50);
ausgabe.setBounds(25,155,230,50);
fenster.add(eingabe);
fenster.add(ausgabe);
fenster.add(schluesselfeld);
}
private void label_create() {
fenster.setLayout(null);
oben = new JLabel("zu entschlüsselnder Text");
mitte = new JLabel("Schlüsselwort");
unten = new JLabel("verschlüsselter Text");
oben.setBounds(27,10,230,15);
mitte.setBounds(27,78,230,15);
unten.setBounds(27,143,230,15);
fenster.add(oben);
fenster.add(mitte);
fenster.add(unten);
}
class Listener_entschluesseln implements ActionListener {
public void actionPerformed(ActionEvent e) {
input= eingabe.getText();
input = input.toUpperCase();
schluessel = schluesselfeld.getText();
schluessel = schluessel.toUpperCase();
Vigenere Buchstabe = new Vigenere(schluessel);
StringBuilder output = new StringBuilder();
for(char i : input.toCharArray())
output.append(Buchstabe.encode(i));
ausgabe.setText(""+output);
dialog_create();
}
}
class Listener_verschluesseln implements ActionListener {
public void actionPerformed(ActionEvent e) {
input= eingabe.getText();
input = input.toUpperCase();
schluessel = schluesselfeld.getText();
schluessel = schluessel.toUpperCase();
Vigenere Buchstabe = new Vigenere(schluessel);
StringBuilder output = new StringBuilder();
String ausgabetext = new String(output);
for(char i : input.toCharArray())
output.append(Buchstabe.decode(i));
ausgabe.setText(""+output);
dialog_create();
}
}
class KopierenAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Clipboard clip=Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection selection=new StringSelection(ausgabe.getText());
clip.setContents(selection,null);
ausgabe.setText("");
eingabe.setText("");
}
}
class LeerenAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
eingabe.setText("");
schluesselfeld.setText("");
ausgabe.setText("");
}
}
class OkAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
}
public Interface() {
fenster = new JFrame("Vigenere-Verschlüsselung");
fenster.setSize(300,300);
fenster.setLocation(300,300);
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button_create();
textfield_create();
label_create();
fenster.setVisible(true);
}
public static void main(String[] args) {
Interface g = new Interface();
}
}