-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
180 lines (145 loc) · 4.79 KB
/
Main.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextArea;
public class Main {
private JFrame frame;
private JTextField FilePathtextField;
private JTextField txtKeyGenerate;
private String filePath;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main window = new Main();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Main() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnPickFile = new JButton("Pick File");
btnPickFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
FilePathtextField.setText(chooser.getSelectedFile().getName());
filePath = chooser.getSelectedFile().getAbsolutePath();
}
}
});
btnPickFile.setBounds(305, 23, 97, 25);
frame.getContentPane().add(btnPickFile);
JButton btnStartProcess = new JButton("Start Process");
btnStartProcess.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread thrd1 = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
BufferedReader br = new BufferedReader(new FileReader(new File(filePath))) ;
String line = "";
int pwd = 0;
int bitp = 0;
while ((line = br.readLine()) != null) {
if (line.contains("password")) {
pwd++;
}else if (line.contains("bitp3123")) {
bitp++;
}
}
txtKeyGenerate.setText(String.valueOf(pwd*bitp));
// process the line.
}catch(Exception e) {
e.printStackTrace();
}
}
}
);
thrd1.start();
}
});
btnStartProcess.setBounds(305, 84, 97, 25);
frame.getContentPane().add(btnStartProcess);
JButton btnSendKey = new JButton("Send Key");
btnSendKey.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread thrd2 = new Thread(new Runnable() {
public void run() {
try {
Socket skt = new Socket("127.0.0.1", 8082);
DataOutputStream out = new DataOutputStream(skt.getOutputStream());
out.write(filePath.getBytes());
skt.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
thrd2.start();
}
});
btnSendKey.setBounds(305, 155, 97, 25);
frame.getContentPane().add(btnSendKey);
JLabel lblFilePath = new JLabel("File Path: ");
lblFilePath.setBounds(12, 27, 77, 16);
frame.getContentPane().add(lblFilePath);
JLabel lblKeyGenerate = new JLabel("Key Generate");
lblKeyGenerate.setBounds(12, 88, 77, 16);
frame.getContentPane().add(lblKeyGenerate);
FilePathtextField = new JTextField();
FilePathtextField.setText("File Path");
FilePathtextField.setBounds(118, 24, 116, 22);
frame.getContentPane().add(FilePathtextField);
FilePathtextField.setColumns(10);
txtKeyGenerate = new JTextField();
txtKeyGenerate.setText("generated key here");
txtKeyGenerate.setBounds(118, 85, 116, 22);
frame.getContentPane().add(txtKeyGenerate);
txtKeyGenerate.setColumns(10);
JLabel lblOutput = new JLabel("Output");
lblOutput.setBounds(12, 134, 56, 16);
frame.getContentPane().add(lblOutput);
JTextArea textArea = new JTextArea();
textArea.setBounds(12, 155, 256, 85);
frame.getContentPane().add(textArea);
}
}