Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 93ae98b

Browse files
committed
add: add User Info Window
1 parent ca57aaa commit 93ae98b

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/main/java/top/mryan2005/managesysteminjava/BasicClass/User.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,16 @@ public void loadUser(String username, SQLLinker sql) {
4848
throw new RuntimeException(e);
4949
}
5050
}
51+
52+
public String getUsername() {
53+
return username;
54+
}
55+
56+
public String getDisplayName() {
57+
return UName;
58+
}
59+
60+
public String getSex() {
61+
return sex;
62+
}
5163
}

src/main/java/top/mryan2005/managesysteminjava/Core.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,17 @@ public void actionPerformed(ActionEvent e) {
192192
gbc.weightx = 0.0; // 当窗口放大时,长度不变
193193
gbc.weighty = 0.0; // 当窗口放大时,高度不变
194194
JButton jButtonRegister = new JButton("Register");
195+
JButton jButtonUserInfo = new JButton("用户个人信息");
196+
JButton jButtonLogout = new JButton("登出");
195197
jButtonRegister.addActionListener(new ActionListener() {
196198
@Override
197199
public void actionPerformed(ActionEvent e) {
198200
createRegisterWindow(jDialog);
199201
if(isLogin) {
200202
jButtonLogin.setEnabled(false);
201203
jButtonRegister.setEnabled(false);
204+
jButtonUserInfo.setEnabled(true);
205+
jButtonLogout.setEnabled(true);
202206
}
203207
}
204208
});
@@ -209,10 +213,54 @@ public void actionPerformed(ActionEvent e) {
209213
if(isLogin) {
210214
jButtonLogin.setEnabled(false);
211215
jButtonRegister.setEnabled(false);
216+
jButtonUserInfo.setEnabled(true);
217+
jButtonLogout.setEnabled(true);
212218
}
213219
}
214220
});
215221
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);
216264
jDialog.setVisible(true);
217265
});
218266
dockBar.add(button3);
@@ -635,6 +683,8 @@ public void actionPerformed(ActionEvent e) {
635683
}
636684
String registerResult = loginPart.register(jTextFieldUsername.getText(), jTextFieldPassword.getText(), jComboBoxSex.getSelectedItem().toString(), jTextFieldDisplayName.getText());
637685
if(registerResult.equals("Success!")) {
686+
currentUser = new User();
687+
currentUser.loadUser(jTextFieldUsername.getText(), sql);
638688
JOptionPane.showMessageDialog(jDialogInput, "注册成功!");
639689
} else {
640690
JOptionPane.showMessageDialog(jDialogInput, registerResult);
@@ -737,6 +787,21 @@ public void actionPerformed(ActionEvent e) {
737787
jDialogInput.setVisible(true);
738788
}
739789

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+
740805
public void createViewWindow() {
741806
final String[] types = {"", ""};
742807
Object[][] data;

0 commit comments

Comments
 (0)