-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayPane.java
More file actions
111 lines (86 loc) · 3.14 KB
/
Copy pathDisplayPane.java
File metadata and controls
111 lines (86 loc) · 3.14 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
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import java.awt.Color;
/**
* Created by plough on 2019/1/3.
*/
class DisplayPane extends JPanel {
private JLabel resHeaderText;
private JTextArea resContentText;
private boolean normalState = true;
private JLabel counterLabel;
private JLabel maxWaitingSecondsLabel;
private int maxWaitingSeconds = 0;
private int counter = 0; // 连续请求次数
DisplayPane() {
initComponents();
}
private void initComponents() {
this.setLayout(new BorderLayout());
this.add(createShowHeaderPane(), BorderLayout.NORTH);
this.add(createShowContentPane(), BorderLayout.CENTER);
}
private JPanel createShowHeaderPane() {
JPanel headerPane = new JPanel();
maxWaitingSecondsLabel = new JLabel("最长等待时间:" + maxWaitingSeconds + "s");
headerPane.add(maxWaitingSecondsLabel);
counterLabel = new JLabel("已连续发送" + counter + "次请求");
counterLabel.setBorder(new EmptyBorder(0, 0, 0, 20));
headerPane.add(counterLabel);
counterLabel.setVisible(false);
final JLabel resHeaderLabel = new JLabel("服务器响应头:");
headerPane.add(resHeaderLabel);
resHeaderText = new JLabel();
headerPane.add(resHeaderText);
return headerPane;
}
private JPanel createShowContentPane() {
JPanel contentPane = new JPanel();
final JLabel resContentLabel = new JLabel("服务器返回内容:");
// resContentLabel.setBounds(10,220,120,25);
contentPane.add(resContentLabel);
resContentText = new JTextArea(25, 50);
resContentText.setLineWrap(true);
// resContentText.setBounds(120,220,465,225);
JScrollPane scrollPane = new JScrollPane();
// scrollPane.setBounds(120,220,465,225);
scrollPane.setViewportView(resContentText);
contentPane.add(scrollPane);
return contentPane;
}
void addCounter() {
counter ++;
counterLabel.setText("已连续发送" + counter + "次请求");
if (!counterLabel.isVisible()) {
counterLabel.setVisible(true);
}
maxWaitingSecondsLabel.setText("最长等待时间:" + maxWaitingSeconds + "s");
}
void initCounter() {
counter = 0;
if (counterLabel.isVisible()) {
counterLabel.setVisible(false);
}
}
void updateMaxWaitingSeconds(int waitingSeconds) {
if (waitingSeconds > maxWaitingSeconds) {
this.maxWaitingSeconds = waitingSeconds;
}
}
void logSwing(String header, String content) {
this.resHeaderText.setText(header);
this.resContentText.setText(content);
checkException(header);
}
boolean isNormalState() {
return normalState;
}
private void checkException(String header) {
normalState = header.contains("200 OK");
this.resHeaderText.setForeground(normalState ? Color.BLACK : Color.RED);
}
}