-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.java
104 lines (80 loc) · 3.24 KB
/
GUI.java
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//Karolien Koorts
import java.awt.*;
import java.awt.event.*;
import java.text.ParseException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.text.MaskFormatter;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.omg.CORBA.PUBLIC_MEMBER;
public class GUI extends JFrame {
String key_value, message;
Encrypt encryption;
boolean encrypt;
Container cp = getContentPane();
public GUI() {
setTitle("Vigenère Cipher");
setDefaultCloseOperation(EXIT_ON_CLOSE);
final JTextArea processed = new JTextArea();
processed.setEditable(false);
processed.setLineWrap(true);
final JTextArea unprocessed = new JTextArea();
unprocessed.setLineWrap(true);
final JTextField key = new JTextField();
final JButton encryptButton = new JButton("Encrypt");
encryptButton.setToolTipText("Click to encrypt message");
final JButton decryptButton = new JButton("Decrypt");
decryptButton.setToolTipText("Click to decrypt message");
JScrollPane scrollPane = new JScrollPane(processed);
scrollPane.setPreferredSize(new Dimension(600, 600));
cp.add(scrollPane, BorderLayout.EAST);
JScrollPane scrollPane2 = new JScrollPane(unprocessed);
scrollPane2.setPreferredSize(new Dimension(600, 600));
cp.add(scrollPane2, BorderLayout.WEST);
JPanel topPanel = new JPanel();
JPanel bottomPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
topPanel.add(new JLabel("Key: ", JLabel.RIGHT));
topPanel.add(key);
//~~~~~~~~~~~~~~~~~~~~~~ENCRYPT BUTTON~~~~~~~~~~~~~~
encryptButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
encrypt = true;
processed.setText(null);
key_value = key.getText();
message = unprocessed.getText();
encryption = new Encrypt(processed, key_value, message, encrypt);
encryption.execute();
}
});
bottomPanel.add(encryptButton);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~DECRYPT BUTTON~~~~~~~~~~~~~~
decryptButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
encrypt = false;
processed.setText(null);
key_value = key.getText();
message = unprocessed.getText();
encryption = new Encrypt(processed, key_value, message, encrypt);
encryption.execute();
}
});
bottomPanel.add(decryptButton);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cp.add(topPanel, BorderLayout.NORTH);
cp.add(bottomPanel, BorderLayout.SOUTH);
pack();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new GUI().setVisible(true);
}
});
}
}