2
2
3
3
import org .apache .commons .codec .binary .Base64 ;
4
4
import org .apache .commons .codec .digest .DigestUtils ;
5
-
5
+ import org . springframework . util . DigestUtils ;
6
6
import javax .swing .*;
7
+ import javax .swing .table .TableColumn ;
7
8
import java .awt .*;
8
9
import java .awt .event .ActionEvent ;
9
10
import java .awt .event .ActionListener ;
11
+ import java .io .UnsupportedEncodingException ;
10
12
import java .util .ArrayList ;
11
13
12
14
public class Entry {
@@ -39,7 +41,7 @@ public String generateHTML() {
39
41
"</head><body>" +
40
42
"<h1>" + simplified_Chinese_character + "</h1>" +
41
43
"<h2>" + traditional_Chinese_character + "</h2>" +
42
- "<p>词组:" + phrases + "</p>" +
44
+ // "<p>词组:" + phrases + "</p>" +
43
45
"<p>梧州话发音:" + Pronunciation_of_Wuzhou + "</p>" +
44
46
"<p>苍梧石桥话发音:" + Pronunciation_of_Cangwu_Shiqiao + "</p>" +
45
47
"<p>蒙山话发音:" + Pronunciation_of_Mengshan + "</p>" +
@@ -62,13 +64,13 @@ public String generateHTML() {
62
64
return html ;
63
65
}
64
66
65
- public String generateCurrentHash () {
67
+ public String generateCurrentHash () throws UnsupportedEncodingException {
66
68
Base64 base64 = new Base64 ();
67
- currentHash = DigestUtils .md5Hex ( base64 . encode ( html .getBytes () ));
69
+ currentHash = DigestUtils .md5DigestAsHex ( html .getBytes ("GBK" ));
68
70
return currentHash ;
69
71
}
70
72
71
- public static void main (String [] args ) {
73
+ public static void main (String [] args ) throws UnsupportedEncodingException {
72
74
Entry entry = new Entry ();
73
75
entry .simplified_Chinese_character = "你" ;
74
76
entry .traditional_Chinese_character = "你" ;
@@ -86,14 +88,93 @@ public static void main(String[] args) {
86
88
entry .Contributors = new ArrayList <>();
87
89
entry .Contributors .add ("mryan2005" );
88
90
entry .Contributors .add ("gungbbogedding" );
89
- JFrame frame = new JFrame ();
90
- frame .setSize (800 , 600 );
91
- frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
91
+ entry .viewEntry (entry );
92
+ }
93
+
94
+ public void viewEntry (Entry entry ) throws UnsupportedEncodingException {
95
+ JFrame jDialog = new JFrame ();
96
+ jDialog .setSize (800 , 600 );
97
+ jDialog .setDefaultCloseOperation (JDialog .DISPOSE_ON_CLOSE );
98
+ jDialog .setLayout (new FlowLayout ());
99
+ entry .generateHTML ();
100
+ entry .generateCurrentHash ();
101
+ JLabel jLabel = new JLabel (entry .generateHTML ());
102
+ jDialog .add (jLabel );
103
+ JButton jButton = new JButton ("编辑" );
104
+ jDialog .add (jButton );
105
+ jButton .addActionListener (new ActionListener () {
106
+ @ Override
107
+ public void actionPerformed (ActionEvent e ) {
108
+ editEntry (jDialog );
109
+ entry .generateHTML ();
110
+ try {
111
+ entry .generateCurrentHash ();
112
+ } catch (UnsupportedEncodingException ex ) {
113
+ throw new RuntimeException (ex );
114
+ }
115
+ jLabel .setText (entry .generateHTML ());
116
+ jLabel .paintImmediately (jLabel .getVisibleRect ());
117
+ }
118
+ });
119
+ jDialog .add (jButton );
120
+ JButton jButton1 = new JButton ("刷新" );
121
+ jDialog .add (jButton1 );
122
+ jButton1 .addActionListener (new ActionListener () {
123
+ @ Override
124
+ public void actionPerformed (ActionEvent e ) {
125
+ entry .generateHTML ();
126
+ try {
127
+ entry .generateCurrentHash ();
128
+ } catch (UnsupportedEncodingException ex ) {
129
+ throw new RuntimeException (ex );
130
+ }
131
+ jLabel .setText (entry .generateHTML ());
132
+ jLabel .paintImmediately (jLabel .getVisibleRect ());
133
+ }
134
+ });
135
+ jDialog .setVisible (true );
136
+ }
137
+
138
+ public void viewEntry (Entry entry , JFrame parentJFrame ) throws UnsupportedEncodingException {
139
+ JDialog jDialog = new JDialog (parentJFrame );
140
+ jDialog .setSize (800 , 600 );
141
+ jDialog .setDefaultCloseOperation (JDialog .DISPOSE_ON_CLOSE );
142
+ jDialog .setLayout (new FlowLayout ());
92
143
entry .generateHTML ();
93
144
entry .generateCurrentHash ();
94
- frame .add (new JLabel (entry .generateHTML ()));
95
- entry .editEntry (frame );
96
- frame .setVisible (true );
145
+ JLabel jLabel = new JLabel (entry .generateHTML ());
146
+ jDialog .add (jLabel );
147
+ JButton jButton = new JButton ("编辑" );
148
+ jDialog .add (jButton );
149
+ jButton .addActionListener (new ActionListener () {
150
+ @ Override
151
+ public void actionPerformed (ActionEvent e ) {
152
+ editEntry (jDialog );
153
+ entry .generateHTML ();
154
+ try {
155
+ entry .generateCurrentHash ();
156
+ } catch (UnsupportedEncodingException ex ) {
157
+ throw new RuntimeException (ex );
158
+ }
159
+ jLabel .setText (entry .generateHTML ());
160
+ }
161
+ });
162
+ jDialog .add (jButton );
163
+ JButton jButton1 = new JButton ("刷新" );
164
+ jDialog .add (jButton1 );
165
+ jButton1 .addActionListener (new ActionListener () {
166
+ @ Override
167
+ public void actionPerformed (ActionEvent e ) {
168
+ entry .generateHTML ();
169
+ try {
170
+ entry .generateCurrentHash ();
171
+ } catch (UnsupportedEncodingException ex ) {
172
+ throw new RuntimeException (ex );
173
+ }
174
+ jLabel .setText (entry .generateHTML ());
175
+ }
176
+ });
177
+ jDialog .setVisible (true );
97
178
}
98
179
99
180
public void editEntry (JFrame parentJFrame ) {
@@ -206,6 +287,17 @@ public void editEntry(JFrame parentJFrame) {
206
287
gridBagConstraints .gridx = 0 ;
207
288
gridBagConstraints .gridy = 12 ;
208
289
gridBagConstraints .gridwidth = 1 ;
290
+ JTable jTable = new JTable ();
291
+ TableColumn tableColumn = new TableColumn ();
292
+ tableColumn .setHeaderValue ("贡献者" );
293
+ jTable .addColumn (tableColumn );
294
+ jDialog .add (jTable , gridBagConstraints );
295
+ gridBagConstraints .gridx = 1 ;
296
+ gridBagConstraints .gridwidth = 3 ;
297
+ jDialog .add (jTable , gridBagConstraints );
298
+ gridBagConstraints .gridx = 0 ;
299
+ gridBagConstraints .gridy = 13 ;
300
+ gridBagConstraints .gridwidth = 1 ;
209
301
JButton jButton = new JButton ("保存" );
210
302
jDialog .add (jButton , gridBagConstraints );
211
303
jButton .addActionListener (new ActionListener () {
@@ -339,6 +431,17 @@ public void editEntry(JDialog parentJDialog) {
339
431
gridBagConstraints .gridx = 0 ;
340
432
gridBagConstraints .gridy = 12 ;
341
433
gridBagConstraints .gridwidth = 1 ;
434
+ JTable jTable = new JTable ();
435
+ TableColumn tableColumn = new TableColumn ();
436
+ tableColumn .setHeaderValue ("贡献者" );
437
+ jTable .addColumn (tableColumn );
438
+ jDialog .add (jTable , gridBagConstraints );
439
+ gridBagConstraints .gridx = 1 ;
440
+ gridBagConstraints .gridwidth = 3 ;
441
+ jDialog .add (jTable , gridBagConstraints );
442
+ gridBagConstraints .gridx = 0 ;
443
+ gridBagConstraints .gridy = 13 ;
444
+ gridBagConstraints .gridwidth = 1 ;
342
445
JButton jButton = new JButton ("保存" );
343
446
jDialog .add (jButton , gridBagConstraints );
344
447
jButton .addActionListener (new ActionListener () {
0 commit comments