-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.java
107 lines (85 loc) · 3.33 KB
/
View.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
105
106
107
import java.awt.event.*;
import javax.swing.*;
public class View extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private Controller controller;
private JPanel mainPanel;
private JPanel textPanel;
private JPanel buttonPanel;
private JPanel labelPanel;
private JPanel textFieldPanel;
private JLabel encryptionKeyLabel;
private JLabel inputTextLabel;
private JLabel outputTextLabel;
private JTextField encryptionKeyTextField;
private JTextField inputTextTextField;
private JTextField outputTextTextField;
private JButton encryptButton;
private JButton decryptButton;
public void setOutputText(String outputText) {
outputTextTextField.setText(outputText);
}
public String getInputText() {
return inputTextTextField.getText();
}
public String getEncryptionKey() {
// get the encryption key from the corresponding text field, and make it an integer
return encryptionKeyTextField.getText();
}
public View(Controller _controller){
this.controller = _controller;
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
textPanel = new JPanel();
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
labelPanel = new JPanel();
labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
textFieldPanel = new JPanel();
textFieldPanel.setLayout(new BoxLayout(textFieldPanel, BoxLayout.Y_AXIS));
buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
textPanel.add(labelPanel);
textPanel.add(textFieldPanel);
mainPanel.add(textPanel);
mainPanel.add(buttonPanel);
encryptionKeyLabel = new JLabel("encryption key", SwingConstants.LEFT);
inputTextLabel = new JLabel("input text", SwingConstants.LEFT);
outputTextLabel = new JLabel("output text", SwingConstants.LEFT);
labelPanel.add(encryptionKeyLabel);
labelPanel.add(inputTextLabel);
labelPanel.add(outputTextLabel);
encryptionKeyTextField = new JTextField();
inputTextTextField = new JTextField();
inputTextTextField.setColumns(18);
outputTextTextField = new JTextField();
textFieldPanel.add(encryptionKeyTextField);
textFieldPanel.add(inputTextTextField);
textFieldPanel.add(outputTextTextField);
encryptButton = new JButton("encrypt");
encryptButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
controller.encryptButtonClicked();
// call corresponding controller method
}
});
decryptButton = new JButton("decrypt");
decryptButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
controller.decryptButtonClicked();
// call corresponding controller method
}
});
buttonPanel.add(encryptButton);
buttonPanel.add(decryptButton);
this.getContentPane().add(mainPanel);
pack();
setVisible(true);
setTitle("I am GUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}