22
33import org .apache .commons .codec .binary .Base64 ;
44import org .apache .commons .codec .digest .DigestUtils ;
5-
5+ import org . springframework . util . DigestUtils ;
66import javax .swing .*;
7+ import javax .swing .table .TableColumn ;
78import java .awt .*;
89import java .awt .event .ActionEvent ;
910import java .awt .event .ActionListener ;
11+ import java .io .UnsupportedEncodingException ;
1012import java .util .ArrayList ;
1113
1214public class Entry {
@@ -39,7 +41,7 @@ public String generateHTML() {
3941 "</head><body>" +
4042 "<h1>" + simplified_Chinese_character + "</h1>" +
4143 "<h2>" + traditional_Chinese_character + "</h2>" +
42- "<p>词组:" + phrases + "</p>" +
44+ // "<p>词组:" + phrases + "</p>" +
4345 "<p>梧州话发音:" + Pronunciation_of_Wuzhou + "</p>" +
4446 "<p>苍梧石桥话发音:" + Pronunciation_of_Cangwu_Shiqiao + "</p>" +
4547 "<p>蒙山话发音:" + Pronunciation_of_Mengshan + "</p>" +
@@ -62,13 +64,13 @@ public String generateHTML() {
6264 return html ;
6365 }
6466
65- public String generateCurrentHash () {
67+ public String generateCurrentHash () throws UnsupportedEncodingException {
6668 Base64 base64 = new Base64 ();
67- currentHash = DigestUtils .md5Hex ( base64 . encode ( html .getBytes () ));
69+ currentHash = DigestUtils .md5DigestAsHex ( html .getBytes ("GBK" ));
6870 return currentHash ;
6971 }
7072
71- public static void main (String [] args ) {
73+ public static void main (String [] args ) throws UnsupportedEncodingException {
7274 Entry entry = new Entry ();
7375 entry .simplified_Chinese_character = "你" ;
7476 entry .traditional_Chinese_character = "你" ;
@@ -86,14 +88,93 @@ public static void main(String[] args) {
8688 entry .Contributors = new ArrayList <>();
8789 entry .Contributors .add ("mryan2005" );
8890 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 ());
92143 entry .generateHTML ();
93144 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 );
97178 }
98179
99180 public void editEntry (JFrame parentJFrame ) {
@@ -206,6 +287,17 @@ public void editEntry(JFrame parentJFrame) {
206287 gridBagConstraints .gridx = 0 ;
207288 gridBagConstraints .gridy = 12 ;
208289 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 ;
209301 JButton jButton = new JButton ("保存" );
210302 jDialog .add (jButton , gridBagConstraints );
211303 jButton .addActionListener (new ActionListener () {
@@ -339,6 +431,17 @@ public void editEntry(JDialog parentJDialog) {
339431 gridBagConstraints .gridx = 0 ;
340432 gridBagConstraints .gridy = 12 ;
341433 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 ;
342445 JButton jButton = new JButton ("保存" );
343446 jDialog .add (jButton , gridBagConstraints );
344447 jButton .addActionListener (new ActionListener () {
0 commit comments