@@ -192,13 +192,17 @@ public void actionPerformed(ActionEvent e) {
192
192
gbc .weightx = 0.0 ; // 当窗口放大时,长度不变
193
193
gbc .weighty = 0.0 ; // 当窗口放大时,高度不变
194
194
JButton jButtonRegister = new JButton ("Register" );
195
+ JButton jButtonUserInfo = new JButton ("用户个人信息" );
196
+ JButton jButtonLogout = new JButton ("登出" );
195
197
jButtonRegister .addActionListener (new ActionListener () {
196
198
@ Override
197
199
public void actionPerformed (ActionEvent e ) {
198
200
createRegisterWindow (jDialog );
199
201
if (isLogin ) {
200
202
jButtonLogin .setEnabled (false );
201
203
jButtonRegister .setEnabled (false );
204
+ jButtonUserInfo .setEnabled (true );
205
+ jButtonLogout .setEnabled (true );
202
206
}
203
207
}
204
208
});
@@ -209,10 +213,54 @@ public void actionPerformed(ActionEvent e) {
209
213
if (isLogin ) {
210
214
jButtonLogin .setEnabled (false );
211
215
jButtonRegister .setEnabled (false );
216
+ jButtonUserInfo .setEnabled (true );
217
+ jButtonLogout .setEnabled (true );
212
218
}
213
219
}
214
220
});
215
221
jDialog .add (jButtonRegister , gbc );
222
+ gbc .gridx = 0 ;
223
+ gbc .gridy = 2 ;
224
+ gbc .gridwidth = 1 ; // 横占一个单元格
225
+ gbc .gridheight = 1 ; // 列占一个单元格
226
+ gbc .weightx = 0.0 ; // 当窗口放大时,长度不变
227
+ gbc .weighty = 0.0 ; // 当窗口放大时,高度不变
228
+ jButtonUserInfo .addActionListener (new ActionListener () {
229
+ @ Override
230
+ public void actionPerformed (ActionEvent e ) {
231
+ if (isLogin ) {
232
+ createUserInfoWindow (jDialog );
233
+ } else {
234
+ JOptionPane .showMessageDialog (jDialog , "请先登录" );
235
+ }
236
+ }
237
+ });
238
+ jDialog .add (jButtonUserInfo , gbc );
239
+ jButtonLogout .addActionListener (new ActionListener () {
240
+ @ Override
241
+ public void actionPerformed (ActionEvent e ) {
242
+ if (isLogin ) {
243
+ isLogin = false ;
244
+ currentUser = null ;
245
+ jButtonLogin .setEnabled (true );
246
+ jButtonRegister .setEnabled (true );
247
+ jButtonUserInfo .setEnabled (false );
248
+ jButtonLogout .setEnabled (false );
249
+ JOptionPane .showMessageDialog (jDialog , "Logout Successfully" );
250
+ } else {
251
+ JOptionPane .showMessageDialog (jDialog , "You are not login" );
252
+ }
253
+ }
254
+ });
255
+ gbc .gridx = 0 ;
256
+ gbc .gridy = 3 ;
257
+ gbc .gridwidth = 1 ; // 横占一个单元格
258
+ gbc .gridheight = 1 ; // 列占一个单元格
259
+ gbc .weightx = 0.0 ; // 当窗口放大时,长度不变
260
+ gbc .weighty = 0.0 ; // 当窗口放大时,高度不变
261
+ jDialog .add (jButtonLogout , gbc );
262
+ jButtonUserInfo .setEnabled (false );
263
+ jButtonLogout .setEnabled (false );
216
264
jDialog .setVisible (true );
217
265
});
218
266
dockBar .add (button3 );
@@ -635,6 +683,8 @@ public void actionPerformed(ActionEvent e) {
635
683
}
636
684
String registerResult = loginPart .register (jTextFieldUsername .getText (), jTextFieldPassword .getText (), jComboBoxSex .getSelectedItem ().toString (), jTextFieldDisplayName .getText ());
637
685
if (registerResult .equals ("Success!" )) {
686
+ currentUser = new User ();
687
+ currentUser .loadUser (jTextFieldUsername .getText (), sql );
638
688
JOptionPane .showMessageDialog (jDialogInput , "注册成功!" );
639
689
} else {
640
690
JOptionPane .showMessageDialog (jDialogInput , registerResult );
@@ -737,6 +787,21 @@ public void actionPerformed(ActionEvent e) {
737
787
jDialogInput .setVisible (true );
738
788
}
739
789
790
+ public void createUserInfoWindow (JDialog owner ) {
791
+ JDialog jDialogUserInfo = new JDialog (owner , "用户信息" , true );
792
+ jDialogUserInfo .setBounds (0 , 0 , 600 , 500 );
793
+ jDialogUserInfo .setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
794
+ jDialogUserInfo .setLayout (new FlowLayout ());
795
+ JLabel jLabel = new JLabel ("<html><body>" +
796
+ "<p style=\" font-size:20px;\" >用户名: " + currentUser .getUsername () + "</p><br/>" +
797
+ "<p style=\" font-size:20px;\" >昵称: " + currentUser .getDisplayName () + "</p><br/>" +
798
+ "<p style=\" font-size:20px;\" >性别: " + currentUser .getSex () + "</p><br/>" +
799
+ "</body></html>"
800
+ );
801
+ jDialogUserInfo .add (jLabel );
802
+ jDialogUserInfo .setVisible (true );
803
+ }
804
+
740
805
public void createViewWindow () {
741
806
final String [] types = {"" , "" };
742
807
Object [][] data ;
0 commit comments