|
|
|
|
@ -6,6 +6,8 @@ import com.mathapp.services.DataPersistence;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.FocusEvent;
|
|
|
|
|
import java.awt.event.FocusListener;
|
|
|
|
|
|
|
|
|
|
public class LoginPanel extends JPanel {
|
|
|
|
|
private final MathApp app;
|
|
|
|
|
@ -23,6 +25,52 @@ public class LoginPanel extends JPanel {
|
|
|
|
|
emailField = new JTextField(20);
|
|
|
|
|
passwordField = new JPasswordField(20);
|
|
|
|
|
|
|
|
|
|
emailField.setText("请输入账号(支持邮箱或用户名)");
|
|
|
|
|
emailField.setForeground(Color.GRAY);
|
|
|
|
|
|
|
|
|
|
passwordField.setText("........");
|
|
|
|
|
passwordField.setForeground(Color.GRAY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emailField.addFocusListener(new FocusListener() {
|
|
|
|
|
public void focusGained(FocusEvent e) {
|
|
|
|
|
// 获得焦点时,若当前文本是提示文字,则清空并改为黑色
|
|
|
|
|
if (emailField.getText().equals("请输入账号(支持邮箱或用户名)")) {
|
|
|
|
|
emailField.setText("");
|
|
|
|
|
emailField.setForeground(Color.black);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void focusLost(FocusEvent e) {
|
|
|
|
|
// 失去焦点时,若文本框为空,则恢复灰色提示文字
|
|
|
|
|
if (emailField.getText().isEmpty()) {
|
|
|
|
|
emailField.setForeground(Color.gray);
|
|
|
|
|
emailField.setText("请输入账号(支持邮箱或用户名)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
passwordField.addFocusListener(new FocusListener() {
|
|
|
|
|
public void focusGained(FocusEvent e) {
|
|
|
|
|
// 获得焦点时,若当前文本是提示文字,则清空并改为黑色
|
|
|
|
|
if (passwordField.getText().equals("........")) {
|
|
|
|
|
passwordField.setText("");
|
|
|
|
|
passwordField.setForeground(Color.black);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void focusLost(FocusEvent e) {
|
|
|
|
|
// 失去焦点时,若文本框为空,则恢复灰色提示文字
|
|
|
|
|
if (passwordField.getText().isEmpty()) {
|
|
|
|
|
passwordField.setForeground(Color.gray);
|
|
|
|
|
passwordField.setText("........");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JButton loginButton = new JButton("登录");
|
|
|
|
|
loginButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
|
|
loginButton.setPreferredSize(new Dimension(120, 40));
|
|
|
|
|
@ -45,7 +93,7 @@ public class LoginPanel extends JPanel {
|
|
|
|
|
gbc.gridwidth = 1;
|
|
|
|
|
gbc.gridy = 1;
|
|
|
|
|
gbc.anchor = GridBagConstraints.EAST;
|
|
|
|
|
add(new JLabel("邮箱:"), gbc);
|
|
|
|
|
//add(new JLabel("账号(用户名或邮箱):"), gbc);
|
|
|
|
|
|
|
|
|
|
gbc.gridx = 1;
|
|
|
|
|
gbc.anchor = GridBagConstraints.WEST;
|
|
|
|
|
@ -54,7 +102,7 @@ public class LoginPanel extends JPanel {
|
|
|
|
|
gbc.gridx = 0;
|
|
|
|
|
gbc.gridy = 2;
|
|
|
|
|
gbc.anchor = GridBagConstraints.EAST;
|
|
|
|
|
add(new JLabel("密码:"), gbc);
|
|
|
|
|
//add(new JLabel("密码:"), gbc);
|
|
|
|
|
|
|
|
|
|
gbc.gridx = 1;
|
|
|
|
|
gbc.anchor = GridBagConstraints.WEST;
|
|
|
|
|
@ -83,7 +131,7 @@ public class LoginPanel extends JPanel {
|
|
|
|
|
String password = new String(passwordField.getPassword());
|
|
|
|
|
|
|
|
|
|
if (email.isEmpty() || password.isEmpty()) {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "邮箱和密码不能为空!", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
JOptionPane.showMessageDialog(this, "账号和密码不能为空!", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -92,7 +140,7 @@ public class LoginPanel extends JPanel {
|
|
|
|
|
app.setCurrentUserEmail(email);
|
|
|
|
|
app.showPanel(MathApp.MAIN_MENU_PANEL);
|
|
|
|
|
} else {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "邮箱或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
JOptionPane.showMessageDialog(this, "账号或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|