-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.java
More file actions
117 lines (87 loc) · 2.84 KB
/
Copy pathMainFrame.java
File metadata and controls
117 lines (87 loc) · 2.84 KB
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
108
109
110
111
112
113
114
115
116
117
package view;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import otp.Message;
public class MainFrame {
private JFrame jFrame;
private String title;
private int width;
private int height;
private JTextField jTextField;
private JLabel jLabel;
private Message message;
public MainFrame(String title, int width, int height, Message message) {
this.jFrame = new JFrame();
this.title = title;
this.width = width;
this.height = height;
this.message = message;
}
public void display() {
this.addNewLabel("Provide Message to Encrypt :");
this.addTextField();
this.addButton();
this.addNewLabel("Cipther Text :");
this.createLabel();
this.adjustFrame();
this.adjustLayout();
this.visible();
}
private void adjustFrame() {
this.jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.jFrame.setTitle(this.title);
this.jFrame.getContentPane().setBackground(Color.GRAY);
this.jFrame.setSize(this.width, this.height);
this.jFrame.setResizable(false);
}
private void visible(){
this.jFrame.setVisible(true);
}
private void adjustLayout(){
this.jFrame.setLayout(new GridLayout(8,1,10,10));
}
public void addTextField() {
this.jTextField = new JTextField();
jTextField.setPreferredSize(new Dimension(250, 40));
this.jFrame.add(jTextField);
}
public void addButton() {
JButton jButton = new JButton();
jButton.setText("Encrypting");
jButton.setBackground(Color.LIGHT_GRAY);
jButton.setBounds(200, 200, 200, 20);
jButton.setFocusable(false);
jButton.addActionListener((e) -> {
String text = this.jTextField.getText();
if(text.length()!=0){
String cipherText = this.message.encrypt(text);
String decryptedMessage =this.message.decrypt();
this.voidDisplayLabel(cipherText,decryptedMessage);
}
});
JPanel jPanel = new JPanel();
jPanel.setBackground(Color.GRAY);
jPanel.add(jButton);
this.jFrame.add(jPanel);
}
public void createLabel() {
this.jLabel = new JLabel();
this.jLabel.setText("");
this.jLabel.setForeground(Color.WHITE);
this.jFrame.add(this.jLabel);
}
public void addNewLabel(String text){
JLabel jLabel = new JLabel();
jLabel.setText(text);
this.jFrame.add(jLabel);
}
public void voidDisplayLabel(String text , String text2) {
jLabel.setText("Encrypted : " + text + " Decrypted :" + text2);
}
}