初学JDBC实现StuInfoManageSystem案例
Source code:https://gitee.com/Qingchen_Jia/student-info-manage-system
关系模式
案例简洁,仅包含两个关系模式:学生和用户。主要目的在于熟悉基础的SQL语句的书写和了解JDBC的基础开发流程。
CREATE SCHEMA if not exists studentinfo;
USE studentinfo;
drop table if exists student;
drop table if exists user;
/* 学生:学号、姓名、专业
用户:账号、密码、身份证号、手机号码 */
create table student
(
Id varchar(12) not null
primary key,
name varchar(12) charset utf8mb3 not null,
major varchar(12) not null
);
create table user
(
username varchar(10) not null
primary key,
password varchar(10) not null,
personId varchar(18) not null,
phoneNum varchar(11) not null
);
连接MySQL数据库
/* 可以都是用static方法或变量,避免不同位置与数据库交互均需new对象 */
package StuInfoManageSystem;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnectMysql {
public Statement statement;
public ConnectMysql() throws ClassNotFoundException, SQLException {
//连接MySQL数据库
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306";
String user = "root"; // 对应修改->本地用户名
String passwd = "123456"; // 对应修改->本地密码
Connection connection = DriverManager.getConnection(url, user, passwd);
statement = connection.createStatement();
}
public Statement getStatement() {
return statement;
}
}
POJO类
学生
package StuInfoManageSystem;
public class Student {
private String id;
private String name;
private String major;
public Student() {
}
public Student(String id, String name, String major) {
this.id = id;
this.name = name;
this.major = major;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
}
用户
package StuInfoManageSystem;
public class User {
private String username;
private String password;
private String personID;
private String phoneNum;
public User() {
}
public User(String username, String password, String personID, String phoneNum) {
this.username = username;
this.password = password;
this.personID = personID;
this.phoneNum = phoneNum;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPersonID() {
return personID;
}
public void setPersonID(String personID) {
this.personID = personID;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
}
工作逻辑
除了基本的增删查以外(数据库表结构简洁,删除后新增足够替代修改功能,可以自己尝试补充更新功能),在登录时增加了验证码逻辑,需要输入忽略大小写区分的验证码才能实现正常登录逻辑。
用户
package StuInfoManageSystem;
import java.sql.*;
import java.util.ArrayList;
import java.util.Random;
public class UserSystem {
private static final Statement STATEMENT;
static {
try {
STATEMENT = new ConnectMysql().getStatement();
} catch (ClassNotFoundException | SQLException e) {
throw new RuntimeException(e);
}
}
public UserSystem() throws SQLException, ClassNotFoundException {
}
public static int cheekUsername(String str) throws SQLException {
//用户名唯一
if (containsUser(str)) {
return 1;
}
//包含大小写字母和数字,且不能为纯数字
for (int i = 0; i < str.length(); i++) {
if (!Character.isLowerCase(str.charAt(i)) && !Character.isUpperCase(str.charAt(i)) && !Character.isDigit(str.charAt(i))) {
return 2;
}
}
boolean flag = false;
for (int i = 0; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i)) || (Character.isLowerCase(str.charAt(i)))) {
flag = true;
break;
}
}
if (!flag) {
return 2;
}
return 0;
}
public static boolean cheekPersonID(String str) {
//长度为18位,前17位均为数字,末位可为数字或‘X’或'x'
return str.matches("[1-9][0-9]{16}[0-9xX]");
}
public static boolean cheekPhoneNum(String str) {
//长度为11位,必须是'1'开头,全部为数字
return str.matches("[1][0-9]{10}");
}
public static void addUser(User user) throws SQLException {
String sql = "INSERT INTO studentinfo.user VALUES ('%s','%s','%s','%s');";
String worksql = String.format(sql, user.getUsername(), user.getPassword(), user.getPersonID(), user.getPhoneNum());
STATEMENT.executeUpdate(worksql);
}
public static ResultSet getUser(String username) throws SQLException {
String sql = "SELECT * FROM studentinfo.user WHERE username='%s';";
String worksql = String.format(sql, username);
return STATEMENT.executeQuery(worksql);
}
public static boolean containsUser(String username) throws SQLException {
return getUser(username).next();
}
public static String getUserPassword(String username) throws SQLException {
ResultSet resultSet = getUser(username);
resultSet.next();
return resultSet.getString("password");
}
public static String getUserPersonId(String username) throws SQLException {
ResultSet resultSet = getUser(username);
resultSet.next();
return resultSet.getString("personId");
}
public static String getUserPhoneNum(String username) throws SQLException {
ResultSet resultSet = getUser(username);
resultSet.next();
return resultSet.getString("phoneNum");
}
public static void updateUserPassword(String username, String password) throws SQLException {
String sql = "UPDATE studentinfo.user SET password='%s' WHERE username='%s';";
String worksql = String.format(sql, password, username);
STATEMENT.executeUpdate(worksql);
}
public static String getCode() {
//长度为5,4位大小写字母和1位数字,位置随机
ArrayList<Character> characters = new ArrayList<>();
for (int i = 0; i < 26; i++) {
characters.add((char) ('a' + i));
}
for (int i = 0; i < 26; i++) {
characters.add((char) ('A' + i));
}
Random index = new Random();
StringBuffer strb = new StringBuffer();
for (int i = 0; i < 4; i++) {
strb.append(characters.get(index.nextInt(characters.size())));
}
strb.append(index.nextInt(10));
char[] arr = strb.toString().toCharArray();
int exchangeIndex = index.nextInt(arr.length);
char temp = arr[exchangeIndex];
arr[exchangeIndex] = arr[arr.length - 1];
arr[arr.length - 1] = temp;
return new String(arr);
}
}
学生
package StuInfoManageSystem;
import java.sql.*;
public class StudentSystem {
private static final Statement STATEMENT;
static {
try {
STATEMENT = new ConnectMysql().getStatement();
} catch (ClassNotFoundException | SQLException e) {
throw new RuntimeException(e);
}
}
public static void deleteStudent(String id) throws SQLException {
//从数据库中删除
String sql = "DELETE FROM studentinfo.student WHERE Id='%s';";
String worksql = String.format(sql, id);
STATEMENT.executeUpdate(worksql);
}
public static boolean contains(String id) throws SQLException {
return getStudent(id).next();
}
public static ResultSet getStudent(String id) throws SQLException {
String sql = "SELECT * FROM studentinfo.student WHERE Id='%s';";
String worksql = String.format(sql, id);
return STATEMENT.executeQuery(worksql);
}
public static ResultSet getAllStudent() throws SQLException {
String sql = "SELECT * FROM studentinfo.student;";
return STATEMENT.executeQuery(sql);
}
public static void addStudent(Student student) throws SQLException {
//添加信息到数据库
String sql = "INSERT INTO studentinfo.student VALUES ('%s','%s','%s');";
String worksql = String.format(sql, student.getId(), student.getName(), student.getMajor());
STATEMENT.executeUpdate(worksql);
}
}
GUI
不建议手写,部分细节打磨过于浪费时间,舍本逐末。建议使用JFormDesigner
插件进行可视化拖拽开发,能够对应生成相应的代码,能够减少大量的时间,同时能够对不同的Java Swing
有更加直观的感受。
登录
package UI;
import StuInfoManageSystem.UserSystem;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import javax.swing.*;
public class LoginFrame extends JFrame {
public LoginFrame() {
initComponents();
this.setVisible(true);
}
private void rightcodeMouseReleased(MouseEvent e) {
// TODO add your code here
String str = UserSystem.getCode();
rightcode.setText(str);
}
private void loginMouseReleased(MouseEvent e) throws SQLException, ClassNotFoundException {
// TODO add your code here
userLogin(inputusername.getText(), new String(inputpassword.getPassword()), inputcode.getText());
}
private void registerMouseReleased(MouseEvent e) {
// TODO add your code here
new RegisterFrame();
this.dispose();
}
private void findpasswordMouseReleased(MouseEvent e) {
// TODO add your code here
new FindPasswdFrame();
this.dispose();
}
private void enterMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
new StudentInfoFrame();
okdialog.dispose();
this.dispose();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
Title = new JLabel();
usrname = new JLabel();
password = new JLabel();
inputusername = new JTextField();
inputpassword = new JPasswordField();
code = new JLabel();
rightcode = new JLabel();
login = new JButton();
register = new JButton();
findpassword = new JButton();
inputcode = new JTextField();
nouserdialog = new JDialog();
nousertext = new JLabel();
errorcodedialog = new JDialog();
errcodetext = new JLabel();
wrongpassworddialog = new JDialog();
wrongpasswordtext = new JLabel();
okdialog = new JDialog();
enter = new JButton();
//======== this ========
setFont(new Font(Font.DIALOG, Font.PLAIN, 14));
setAlwaysOnTop(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
var contentPane = getContentPane();
contentPane.setLayout(null);
//---- Title ----
Title.setText("\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf");
Title.setFont(Title.getFont().deriveFont(Title.getFont().getStyle() & ~Font.ITALIC, Title.getFont().getSize() + 15f));
contentPane.add(Title);
Title.setBounds(new Rectangle(new Point(130, 40), Title.getPreferredSize()));
//---- usrname ----
usrname.setText("\u7528\u6237\u540d\uff1a");
usrname.setFont(usrname.getFont().deriveFont(usrname.getFont().getSize() + 6f));
contentPane.add(usrname);
usrname.setBounds(new Rectangle(new Point(70, 95), usrname.getPreferredSize()));
//---- password ----
password.setText("\u5bc6\u7801\uff1a");
password.setFont(password.getFont().deriveFont(password.getFont().getSize() + 6f));
contentPane.add(password);
password.setBounds(new Rectangle(new Point(85, 135), password.getPreferredSize()));
contentPane.add(inputusername);
inputusername.setBounds(145, 95, 230, 25);
contentPane.add(inputpassword);
inputpassword.setBounds(145, 135, 230, 25);
//---- code ----
code.setText("\u9a8c\u8bc1\u7801\uff1a");
code.setFont(code.getFont().deriveFont(code.getFont().getSize() + 6f));
contentPane.add(code);
code.setBounds(new Rectangle(new Point(70, 175), code.getPreferredSize()));
//---- rightcode ----
rightcode.setText("\u70b9\u6211\uff01");
rightcode.setFont(rightcode.getFont().deriveFont(rightcode.getFont().getSize() + 3f));
rightcode.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
rightcodeMouseReleased(e);
}
});
contentPane.add(rightcode);
rightcode.setBounds(220, 180, 60, 20);
//---- login ----
login.setText("\u767b\u5f55");
login.setFont(login.getFont().deriveFont(Font.BOLD, login.getFont().getSize() + 6f));
login.setFocusPainted(false);
login.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
loginMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(login);
login.setBounds(new Rectangle(new Point(145, 215), login.getPreferredSize()));
//---- register ----
register.setText("\u6ce8\u518c");
register.setFont(register.getFont().deriveFont(Font.BOLD, register.getFont().getSize() + 6f));
register.setFocusPainted(false);
register.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
registerMouseReleased(e);
}
});
contentPane.add(register);
register.setBounds(new Rectangle(new Point(295, 215), register.getPreferredSize()));
//---- findpassword ----
findpassword.setText("\u5fd8\u8bb0\u5bc6\u7801");
findpassword.setFont(findpassword.getFont().deriveFont(Font.BOLD));
findpassword.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
findpasswordMouseReleased(e);
}
});
contentPane.add(findpassword);
findpassword.setBounds(380, 135, findpassword.getPreferredSize().width, 25);
contentPane.add(inputcode);
inputcode.setBounds(145, 175, 65, 25);
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
setSize(520, 330);
setLocationRelativeTo(getOwner());
//======== nouserdialog ========
{
nouserdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
nouserdialog.setAlwaysOnTop(true);
nouserdialog.setModal(true);
var nouserdialogContentPane = nouserdialog.getContentPane();
nouserdialogContentPane.setLayout(null);
//---- nousertext ----
nousertext.setText("\u5f53\u524d\u7528\u6237\u4e0d\u5b58\u5728\uff01\u8bf7\u5148\u6ce8\u518c");
nousertext.setFont(nousertext.getFont().deriveFont(nousertext.getFont().getSize() + 7f));
nouserdialogContentPane.add(nousertext);
nousertext.setBounds(new Rectangle(new Point(45, 35), nousertext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < nouserdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = nouserdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = nouserdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
nouserdialogContentPane.setMinimumSize(preferredSize);
nouserdialogContentPane.setPreferredSize(preferredSize);
}
nouserdialog.setSize(345, 130);
nouserdialog.setLocationRelativeTo(nouserdialog.getOwner());
}
//======== errorcodedialog ========
{
errorcodedialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorcodedialog.setAlwaysOnTop(true);
errorcodedialog.setModal(true);
var errorcodedialogContentPane = errorcodedialog.getContentPane();
errorcodedialogContentPane.setLayout(null);
//---- errcodetext ----
errcodetext.setText("\u9a8c\u8bc1\u7801\u4e0d\u5339\u914d\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errcodetext.setFont(errcodetext.getFont().deriveFont(errcodetext.getFont().getSize() + 7f));
errorcodedialogContentPane.add(errcodetext);
errcodetext.setBounds(new Rectangle(new Point(45, 35), errcodetext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorcodedialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorcodedialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorcodedialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorcodedialogContentPane.setMinimumSize(preferredSize);
errorcodedialogContentPane.setPreferredSize(preferredSize);
}
errorcodedialog.setSize(345, 130);
errorcodedialog.setLocationRelativeTo(errorcodedialog.getOwner());
}
//======== wrongpassworddialog ========
{
wrongpassworddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
wrongpassworddialog.setAlwaysOnTop(true);
wrongpassworddialog.setModal(true);
var wrongpassworddialogContentPane = wrongpassworddialog.getContentPane();
wrongpassworddialogContentPane.setLayout(null);
//---- wrongpasswordtext ----
wrongpasswordtext.setText("\u5bc6\u7801\u8f93\u5165\u9519\u8bef\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
wrongpasswordtext.setFont(wrongpasswordtext.getFont().deriveFont(wrongpasswordtext.getFont().getSize() + 7f));
wrongpassworddialogContentPane.add(wrongpasswordtext);
wrongpasswordtext.setBounds(new Rectangle(new Point(45, 35), wrongpasswordtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < wrongpassworddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = wrongpassworddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = wrongpassworddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
wrongpassworddialogContentPane.setMinimumSize(preferredSize);
wrongpassworddialogContentPane.setPreferredSize(preferredSize);
}
wrongpassworddialog.setSize(345, 130);
wrongpassworddialog.setLocationRelativeTo(wrongpassworddialog.getOwner());
}
//======== okdialog ========
{
okdialog.setAlwaysOnTop(true);
okdialog.setModal(true);
okdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
var okdialogContentPane = okdialog.getContentPane();
okdialogContentPane.setLayout(null);
//---- enter ----
enter.setText("\u767b\u9646\u6210\u529f\uff01\u8fdb\u5165\u7cfb\u7edf");
enter.setFont(enter.getFont().deriveFont(enter.getFont().getSize() + 7f));
enter.setFocusPainted(false);
enter.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
enterMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
okdialogContentPane.add(enter);
enter.setBounds(new Rectangle(new Point(55, 35), enter.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < okdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = okdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = okdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
okdialogContentPane.setMinimumSize(preferredSize);
okdialogContentPane.setPreferredSize(preferredSize);
}
okdialog.setSize(345, 130);
okdialog.setLocationRelativeTo(okdialog.getOwner());
}
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
private JLabel Title;
private JLabel usrname;
private JLabel password;
private JTextField inputusername;
private JPasswordField inputpassword;
private JLabel code;
private JLabel rightcode;
private JButton login;
private JButton register;
private JButton findpassword;
private JTextField inputcode;
private JDialog nouserdialog;
private JLabel nousertext;
private JDialog errorcodedialog;
private JLabel errcodetext;
private JDialog wrongpassworddialog;
private JLabel wrongpasswordtext;
private JDialog okdialog;
private JButton enter;
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
public void userLogin(String usernameIn, String passwordIn, String codeIn) throws SQLException, ClassNotFoundException {
//判断是否存在此用户名的用户
if (!UserSystem.containsUser(usernameIn)) {
nouserdialog.setVisible(true);
return;
}
//输入验证码验证
if (!codeIn.equalsIgnoreCase(rightcode.getText())) {
errorcodedialog.setVisible(true);
return;
}
//判断密码对错
if (!UserSystem.getUserPassword(usernameIn).equals(passwordIn)) {
wrongpassworddialog.setVisible(true);
return;
}
okdialog.setVisible(true);
}
}
注册
package UI;
import java.awt.event.*;
import StuInfoManageSystem.User;
import StuInfoManageSystem.UserSystem;
import java.awt.*;
import java.sql.SQLException;
import javax.swing.*;
public class RegisterFrame extends JFrame {
public RegisterFrame() {
initComponents();
this.setVisible(true);
}
private void checkusernameMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
//判断用户名是否可用
switch (UserSystem.cheekUsername(inputusername.getText())) {
case 0 -> {
;
}
case 1 -> existusernamedialog.setVisible(true);
case 2 -> errorusernamedialog.setVisible(true);
}
}
private void checkpasswordMouseReleased(MouseEvent e) {
// TODO add your code here
//判断密码是否确认
if (!new String(inputpasswrodagain.getPassword()).equals(new String(inputpassword.getPassword()))) {
differentpassworddialog.setVisible(true);
}
}
private void checkpersonidMouseReleased(MouseEvent e) {
// TODO add your code here
//判断身份证格式
if (!UserSystem.cheekPersonID(inputpersonid.getText())) {
errorpersoniddialog.setVisible(true);
}
}
private void checkphonenumMouseReleased(MouseEvent e) {
// TODO add your code here
//判断手机号格式
if (!UserSystem.cheekPhoneNum(inputphonenum.getText())) {
errorphonenumdialog.setVisible(true);
}
}
private void registerMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
userRegister(inputusername.getText(), new String(inputpassword.getPassword()), new String(inputpasswrodagain.getPassword()), inputpersonid.getText(), inputphonenum.getText());
}
private void exitMouseReleased(MouseEvent e) {
// TODO add your code here
new LoginFrame();
this.dispose();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
Title = new JLabel();
usrname = new JLabel();
password = new JLabel();
inputusername = new JTextField();
inputpassword = new JPasswordField();
register = new JButton();
personid = new JLabel();
passwordagain = new JLabel();
inputpasswrodagain = new JPasswordField();
inputpersonid = new JTextField();
phonenum = new JLabel();
inputphonenum = new JTextField();
checkusername = new JButton();
checkpersonid = new JButton();
checkphonenum = new JButton();
checkpassword = new JButton();
exit = new JButton();
existusernamedialog = new JDialog();
existusernametext = new JLabel();
errorusernamedialog = new JDialog();
errorusernametext = new JLabel();
differentpassworddialog = new JDialog();
differentpasswordtext = new JLabel();
errorpersoniddialog = new JDialog();
errorpersonidtext = new JLabel();
errorphonenumdialog = new JDialog();
errorphonenumtext = new JLabel();
okdialog = new JDialog();
oktext = new JLabel();
//======== this ========
setFont(new Font(Font.DIALOG, Font.PLAIN, 14));
setAlwaysOnTop(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
var contentPane = getContentPane();
contentPane.setLayout(null);
//---- Title ----
Title.setText("\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf");
Title.setFont(Title.getFont().deriveFont(Title.getFont().getStyle() & ~Font.ITALIC, Title.getFont().getSize() + 15f));
contentPane.add(Title);
Title.setBounds(new Rectangle(new Point(130, 40), Title.getPreferredSize()));
//---- usrname ----
usrname.setText("\u7528\u6237\u540d\uff1a");
usrname.setFont(usrname.getFont().deriveFont(usrname.getFont().getSize() + 6f));
contentPane.add(usrname);
usrname.setBounds(new Rectangle(new Point(70, 95), usrname.getPreferredSize()));
//---- password ----
password.setText("\u5bc6\u7801\uff1a");
password.setFont(password.getFont().deriveFont(password.getFont().getSize() + 6f));
contentPane.add(password);
password.setBounds(new Rectangle(new Point(85, 135), password.getPreferredSize()));
contentPane.add(inputusername);
inputusername.setBounds(145, 95, 230, 25);
contentPane.add(inputpassword);
inputpassword.setBounds(145, 135, 230, 25);
//---- register ----
register.setText("\u6ce8\u518c");
register.setFont(register.getFont().deriveFont(Font.BOLD, register.getFont().getSize() + 6f));
register.setFocusPainted(false);
register.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
registerMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(register);
register.setBounds(new Rectangle(new Point(220, 310), register.getPreferredSize()));
//---- personid ----
personid.setText("\u8eab\u4efd\u8bc1\u53f7\uff1a");
personid.setFont(personid.getFont().deriveFont(personid.getFont().getSize() + 6f));
contentPane.add(personid);
personid.setBounds(new Rectangle(new Point(50, 215), personid.getPreferredSize()));
//---- passwordagain ----
passwordagain.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
passwordagain.setFont(passwordagain.getFont().deriveFont(passwordagain.getFont().getSize() + 6f));
contentPane.add(passwordagain);
passwordagain.setBounds(new Rectangle(new Point(50, 175), passwordagain.getPreferredSize()));
contentPane.add(inputpasswrodagain);
inputpasswrodagain.setBounds(145, 175, 230, 25);
contentPane.add(inputpersonid);
inputpersonid.setBounds(145, 215, 230, 25);
//---- phonenum ----
phonenum.setText("\u624b\u673a\u53f7\uff1a");
phonenum.setFont(phonenum.getFont().deriveFont(phonenum.getFont().getSize() + 6f));
contentPane.add(phonenum);
phonenum.setBounds(new Rectangle(new Point(65, 255), phonenum.getPreferredSize()));
contentPane.add(inputphonenum);
inputphonenum.setBounds(145, 255, 230, 25);
//---- checkusername ----
checkusername.setText("\u68c0\u9a8c");
checkusername.setFont(checkusername.getFont().deriveFont(checkusername.getFont().getStyle() | Font.BOLD));
checkusername.setFocusPainted(false);
checkusername.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
checkusernameMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(checkusername);
checkusername.setBounds(395, 95, checkusername.getPreferredSize().width, 25);
//---- checkpersonid ----
checkpersonid.setText("\u68c0\u9a8c");
checkpersonid.setFont(checkpersonid.getFont().deriveFont(checkpersonid.getFont().getStyle() | Font.BOLD));
checkpersonid.setFocusPainted(false);
checkpersonid.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
checkpersonidMouseReleased(e);
}
});
contentPane.add(checkpersonid);
checkpersonid.setBounds(395, 215, checkpersonid.getPreferredSize().width, 25);
//---- checkphonenum ----
checkphonenum.setText("\u68c0\u9a8c");
checkphonenum.setFont(checkphonenum.getFont().deriveFont(checkphonenum.getFont().getStyle() | Font.BOLD));
checkphonenum.setFocusPainted(false);
checkphonenum.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
checkphonenumMouseReleased(e);
}
});
contentPane.add(checkphonenum);
checkphonenum.setBounds(395, 255, checkphonenum.getPreferredSize().width, 25);
//---- checkpassword ----
checkpassword.setText("\u68c0\u9a8c");
checkpassword.setFont(checkpassword.getFont().deriveFont(checkpassword.getFont().getStyle() | Font.BOLD));
checkpassword.setFocusPainted(false);
checkpassword.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
checkpasswordMouseReleased(e);
}
});
contentPane.add(checkpassword);
checkpassword.setBounds(395, 175, checkpassword.getPreferredSize().width, 25);
//---- exit ----
exit.setText("\u8fd4\u56de");
exit.setFont(exit.getFont().deriveFont(Font.BOLD, exit.getFont().getSize() + 6f));
exit.setFocusPainted(false);
exit.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
exitMouseReleased(e);
}
});
contentPane.add(exit);
exit.setBounds(new Rectangle(new Point(220, 350), exit.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
setSize(520, 435);
setLocationRelativeTo(getOwner());
//======== existusernamedialog ========
{
existusernamedialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
existusernamedialog.setAlwaysOnTop(true);
existusernamedialog.setModal(true);
var existusernamedialogContentPane = existusernamedialog.getContentPane();
existusernamedialogContentPane.setLayout(null);
//---- existusernametext ----
existusernametext.setText("\u7528\u6237\u540d\u5df2\u88ab\u5360\u7528\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
existusernametext.setFont(existusernametext.getFont().deriveFont(existusernametext.getFont().getSize() + 7f));
existusernamedialogContentPane.add(existusernametext);
existusernametext.setBounds(new Rectangle(new Point(45, 35), existusernametext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < existusernamedialogContentPane.getComponentCount(); i++) {
Rectangle bounds = existusernamedialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = existusernamedialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
existusernamedialogContentPane.setMinimumSize(preferredSize);
existusernamedialogContentPane.setPreferredSize(preferredSize);
}
existusernamedialog.setSize(345, 130);
existusernamedialog.setLocationRelativeTo(existusernamedialog.getOwner());
}
//======== errorusernamedialog ========
{
errorusernamedialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorusernamedialog.setAlwaysOnTop(true);
errorusernamedialog.setModal(true);
var errorusernamedialogContentPane = errorusernamedialog.getContentPane();
errorusernamedialogContentPane.setLayout(null);
//---- errorusernametext ----
errorusernametext.setText("\u7528\u6237\u540d\u683c\u5f0f\u9519\u8bef\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errorusernametext.setFont(errorusernametext.getFont().deriveFont(errorusernametext.getFont().getSize() + 7f));
errorusernamedialogContentPane.add(errorusernametext);
errorusernametext.setBounds(new Rectangle(new Point(45, 35), errorusernametext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorusernamedialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorusernamedialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorusernamedialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorusernamedialogContentPane.setMinimumSize(preferredSize);
errorusernamedialogContentPane.setPreferredSize(preferredSize);
}
errorusernamedialog.setSize(345, 130);
errorusernamedialog.setLocationRelativeTo(errorusernamedialog.getOwner());
}
//======== differentpassworddialog ========
{
differentpassworddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
differentpassworddialog.setAlwaysOnTop(true);
differentpassworddialog.setModal(true);
var differentpassworddialogContentPane = differentpassworddialog.getContentPane();
differentpassworddialogContentPane.setLayout(null);
//---- differentpasswordtext ----
differentpasswordtext.setText("\u4e24\u6b21\u5bc6\u7801\u4e0d\u4e00\u81f4\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
differentpasswordtext.setFont(differentpasswordtext.getFont().deriveFont(differentpasswordtext.getFont().getSize() + 7f));
differentpassworddialogContentPane.add(differentpasswordtext);
differentpasswordtext.setBounds(new Rectangle(new Point(45, 35), differentpasswordtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < differentpassworddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = differentpassworddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = differentpassworddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
differentpassworddialogContentPane.setMinimumSize(preferredSize);
differentpassworddialogContentPane.setPreferredSize(preferredSize);
}
differentpassworddialog.setSize(345, 130);
differentpassworddialog.setLocationRelativeTo(differentpassworddialog.getOwner());
}
//======== errorpersoniddialog ========
{
errorpersoniddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorpersoniddialog.setAlwaysOnTop(true);
errorpersoniddialog.setModal(true);
var errorpersoniddialogContentPane = errorpersoniddialog.getContentPane();
errorpersoniddialogContentPane.setLayout(null);
//---- errorpersonidtext ----
errorpersonidtext.setText("\u8eab\u4efd\u8bc1\u683c\u5f0f\u9519\u8bef\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errorpersonidtext.setFont(errorpersonidtext.getFont().deriveFont(errorpersonidtext.getFont().getSize() + 7f));
errorpersoniddialogContentPane.add(errorpersonidtext);
errorpersonidtext.setBounds(new Rectangle(new Point(45, 35), errorpersonidtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorpersoniddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorpersoniddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorpersoniddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorpersoniddialogContentPane.setMinimumSize(preferredSize);
errorpersoniddialogContentPane.setPreferredSize(preferredSize);
}
errorpersoniddialog.setSize(345, 130);
errorpersoniddialog.setLocationRelativeTo(errorpersoniddialog.getOwner());
}
//======== errorphonenumdialog ========
{
errorphonenumdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorphonenumdialog.setAlwaysOnTop(true);
errorphonenumdialog.setModal(true);
var errorphonenumdialogContentPane = errorphonenumdialog.getContentPane();
errorphonenumdialogContentPane.setLayout(null);
//---- errorphonenumtext ----
errorphonenumtext.setText("\u624b\u673a\u53f7\u683c\u5f0f\u9519\u8bef\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errorphonenumtext.setFont(errorphonenumtext.getFont().deriveFont(errorphonenumtext.getFont().getSize() + 7f));
errorphonenumdialogContentPane.add(errorphonenumtext);
errorphonenumtext.setBounds(new Rectangle(new Point(45, 35), errorphonenumtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorphonenumdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorphonenumdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorphonenumdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorphonenumdialogContentPane.setMinimumSize(preferredSize);
errorphonenumdialogContentPane.setPreferredSize(preferredSize);
}
errorphonenumdialog.setSize(345, 130);
errorphonenumdialog.setLocationRelativeTo(errorphonenumdialog.getOwner());
}
//======== okdialog ========
{
okdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
okdialog.setAlwaysOnTop(true);
okdialog.setModal(true);
var okdialogContentPane = okdialog.getContentPane();
okdialogContentPane.setLayout(null);
//---- oktext ----
oktext.setText("\u8d26\u6237\u6ce8\u518c\u6210\u529f\uff01\u8bf7\u8fd4\u56de\u767b\u5f55");
oktext.setFont(oktext.getFont().deriveFont(oktext.getFont().getSize() + 7f));
okdialogContentPane.add(oktext);
oktext.setBounds(new Rectangle(new Point(45, 35), oktext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < okdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = okdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = okdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
okdialogContentPane.setMinimumSize(preferredSize);
okdialogContentPane.setPreferredSize(preferredSize);
}
okdialog.setSize(345, 130);
okdialog.setLocationRelativeTo(okdialog.getOwner());
}
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
private JLabel Title;
private JLabel usrname;
private JLabel password;
private JTextField inputusername;
private JPasswordField inputpassword;
private JButton register;
private JLabel personid;
private JLabel passwordagain;
private JPasswordField inputpasswrodagain;
private JTextField inputpersonid;
private JLabel phonenum;
private JTextField inputphonenum;
private JButton checkusername;
private JButton checkpersonid;
private JButton checkphonenum;
private JButton checkpassword;
private JButton exit;
private JDialog existusernamedialog;
private JLabel existusernametext;
private JDialog errorusernamedialog;
private JLabel errorusernametext;
private JDialog differentpassworddialog;
private JLabel differentpasswordtext;
private JDialog errorpersoniddialog;
private JLabel errorpersonidtext;
private JDialog errorphonenumdialog;
private JLabel errorphonenumtext;
private JDialog okdialog;
private JLabel oktext;
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
public void userRegister(String usernameIn, String passwordIn, String passwordagainIn, String personidIn, String phonenumIn) throws SQLException {
User user = new User();
//判断用户名是否可用
switch (UserSystem.cheekUsername(usernameIn)) {
case 0 -> user.setUsername(usernameIn);
case 1 -> {
existusernamedialog.setVisible(true);
return;
}
case 2 -> {
errorusernamedialog.setVisible(true);
return;
}
}
//判断密码是否确认
if (passwordagainIn.equals(passwordIn)) {
user.setPassword(passwordagainIn);
} else {
differentpassworddialog.setVisible(true);
return;
}
//判断身份证格式
if (UserSystem.cheekPersonID(personidIn)) {
user.setPersonID(personidIn);
} else {
errorpersoniddialog.setVisible(true);
return;
}
//判断手机号格式
if (UserSystem.cheekPhoneNum(phonenumIn)) {
user.setPhoneNum(phonenumIn);
} else {
errorphonenumdialog.setVisible(true);
return;
}
UserSystem.addUser(user);
okdialog.setVisible(true);
}
}
找回密码
package UI;
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import StuInfoManageSystem.Student;
import StuInfoManageSystem.StudentSystem;
public class StudentInfoFrame extends JFrame {
public StudentInfoFrame() throws SQLException {
initComponents();
studentQuery();
this.setVisible(true);
}
private void queryMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
ResultSet resultSet = StudentSystem.getStudent(inputidquery.getText());
//判断有无结果
if (!resultSet.next()) {
nostudentdialog.setVisible(true);
return;
} else {
//将查询数据放入容器
getidtext.setText(resultSet.getString(1));
getnametext.setText(resultSet.getString(2));
getmajortext.setText(resultSet.getString(3));
querydialog.setVisible(true);
}
}
private void addMouseReleased(MouseEvent e) {
// TODO add your code here
adddialog.setVisible(true);
}
private void exitMouseReleased(MouseEvent e) {
// TODO add your code here
new LoginFrame();
this.dispose();
}
private void deleteMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
StudentSystem.deleteStudent(inputiddelete.getText());
deleteokdialog.setVisible(true);
}
private void addokbuttonMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
addokdialog.dispose();
adddialog.dispose();
this.dispose();
new StudentInfoFrame();
}
private void deleteokbuttonMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
deleteokdialog.dispose();
this.dispose();
new StudentInfoFrame();
}
private void confirmbuttonMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
studentAdd(addidtext.getText(), addnametext.getText(), addmajortext.getText());
addokdialog.setVisible(true);
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
systemname = new JLabel();
title = new JScrollPane();
table = new JTable();
query = new JButton();
add = new JButton();
delete = new JButton();
inputidquery = new JTextField();
exit = new JButton();
inputiddelete = new JTextField();
querydialog = new JDialog();
getid = new JLabel();
getname = new JLabel();
getmajor = new JLabel();
getidtext = new JLabel();
getnametext = new JLabel();
getmajortext = new JLabel();
nostudentdialog = new JDialog();
nostudenttext = new JLabel();
adddialog = new JDialog();
addid = new JLabel();
addname = new JLabel();
addmajor = new JLabel();
addidtext = new JTextField();
addnametext = new JTextField();
addmajortext = new JTextField();
confirmbutton = new JButton();
existstudentdialog = new JDialog();
existstudenttext = new JLabel();
addokdialog = new JDialog();
addokbutton = new JButton();
deleteokdialog = new JDialog();
deleteokbutton = new JButton();
//======== this ========
setAlwaysOnTop(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
var contentPane = getContentPane();
contentPane.setLayout(null);
//---- systemname ----
systemname.setText("\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf");
systemname.setFont(systemname.getFont().deriveFont(systemname.getFont().getSize() + 18f));
contentPane.add(systemname);
systemname.setBounds(new Rectangle(new Point(215, 20), systemname.getPreferredSize()));
//======== title ========
{
//---- table ----
table.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 16));
table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"\u5b66\u53f7", "\u59d3\u540d", "\u4e13\u4e1a"
}
));
table.setRowHeight(25);
title.setViewportView(table);
}
contentPane.add(title);
title.setBounds(0, 100, 695, 150);
//---- query ----
query.setText("\u67e5\u8be2");
query.setFont(query.getFont().deriveFont(query.getFont().getSize() + 7f));
query.setFocusPainted(false);
query.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
queryMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(query);
query.setBounds(new Rectangle(new Point(600, 60), query.getPreferredSize()));
//---- add ----
add.setText("\u6dfb\u52a0");
add.setFont(add.getFont().deriveFont(add.getFont().getSize() + 7f));
add.setFocusPainted(false);
add.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
addMouseReleased(e);
}
});
contentPane.add(add);
add.setBounds(new Rectangle(new Point(15, 275), add.getPreferredSize()));
//---- delete ----
delete.setText("\u5220\u9664");
delete.setFont(delete.getFont().deriveFont(delete.getFont().getSize() + 7f));
delete.setFocusPainted(false);
delete.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
deleteMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(delete);
delete.setBounds(new Rectangle(new Point(15, 60), delete.getPreferredSize()));
contentPane.add(inputidquery);
inputidquery.setBounds(465, 65, 125, inputidquery.getPreferredSize().height);
//---- exit ----
exit.setText("\u9000\u51fa");
exit.setFont(exit.getFont().deriveFont(exit.getFont().getSize() + 7f));
exit.setFocusPainted(false);
exit.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
exitMouseReleased(e);
}
});
contentPane.add(exit);
exit.setBounds(new Rectangle(new Point(595, 275), exit.getPreferredSize()));
contentPane.add(inputiddelete);
inputiddelete.setBounds(95, 65, 125, inputiddelete.getPreferredSize().height);
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
setSize(695, 360);
setLocationRelativeTo(getOwner());
//======== querydialog ========
{
querydialog.setAlwaysOnTop(true);
querydialog.setModal(true);
querydialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
var querydialogContentPane = querydialog.getContentPane();
querydialogContentPane.setLayout(null);
//---- getid ----
getid.setText("\u5b66\u53f7\uff1a");
getid.setFont(getid.getFont().deriveFont(getid.getFont().getSize() + 8f));
querydialogContentPane.add(getid);
getid.setBounds(new Rectangle(new Point(65, 35), getid.getPreferredSize()));
//---- getname ----
getname.setText("\u59d3\u540d\uff1a");
getname.setFont(getname.getFont().deriveFont(getname.getFont().getSize() + 8f));
querydialogContentPane.add(getname);
getname.setBounds(new Rectangle(new Point(65, 75), getname.getPreferredSize()));
//---- getmajor ----
getmajor.setText("\u4e13\u4e1a\uff1a");
getmajor.setFont(getmajor.getFont().deriveFont(getmajor.getFont().getSize() + 8f));
querydialogContentPane.add(getmajor);
getmajor.setBounds(new Rectangle(new Point(65, 115), getmajor.getPreferredSize()));
//---- getidtext ----
getidtext.setBorder(LineBorder.createBlackLineBorder());
querydialogContentPane.add(getidtext);
getidtext.setBounds(130, 35, 200, 25);
//---- getnametext ----
getnametext.setBorder(LineBorder.createBlackLineBorder());
querydialogContentPane.add(getnametext);
getnametext.setBounds(130, 75, 200, 25);
//---- getmajortext ----
getmajortext.setBorder(LineBorder.createBlackLineBorder());
querydialogContentPane.add(getmajortext);
getmajortext.setBounds(130, 115, 200, 25);
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < querydialogContentPane.getComponentCount(); i++) {
Rectangle bounds = querydialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = querydialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
querydialogContentPane.setMinimumSize(preferredSize);
querydialogContentPane.setPreferredSize(preferredSize);
}
querydialog.setSize(430, 200);
querydialog.setLocationRelativeTo(querydialog.getOwner());
}
//======== nostudentdialog ========
{
nostudentdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
nostudentdialog.setAlwaysOnTop(true);
nostudentdialog.setModal(true);
var nostudentdialogContentPane = nostudentdialog.getContentPane();
nostudentdialogContentPane.setLayout(null);
//---- nostudenttext ----
nostudenttext.setText("\u8be5\u5b66\u751f\u4e0d\u5b58\u5728\uff01");
nostudenttext.setFont(nostudenttext.getFont().deriveFont(nostudenttext.getFont().getSize() + 7f));
nostudentdialogContentPane.add(nostudenttext);
nostudenttext.setBounds(new Rectangle(new Point(45, 35), nostudenttext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < nostudentdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = nostudentdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = nostudentdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
nostudentdialogContentPane.setMinimumSize(preferredSize);
nostudentdialogContentPane.setPreferredSize(preferredSize);
}
nostudentdialog.setSize(265, 130);
nostudentdialog.setLocationRelativeTo(nostudentdialog.getOwner());
}
//======== adddialog ========
{
adddialog.setAlwaysOnTop(true);
adddialog.setModal(true);
adddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
var adddialogContentPane = adddialog.getContentPane();
adddialogContentPane.setLayout(null);
//---- addid ----
addid.setText("\u5b66\u53f7\uff1a");
addid.setFont(addid.getFont().deriveFont(addid.getFont().getSize() + 8f));
adddialogContentPane.add(addid);
addid.setBounds(new Rectangle(new Point(65, 35), addid.getPreferredSize()));
//---- addname ----
addname.setText("\u59d3\u540d\uff1a");
addname.setFont(addname.getFont().deriveFont(addname.getFont().getSize() + 8f));
adddialogContentPane.add(addname);
addname.setBounds(new Rectangle(new Point(65, 75), addname.getPreferredSize()));
//---- addmajor ----
addmajor.setText("\u4e13\u4e1a\uff1a");
addmajor.setFont(addmajor.getFont().deriveFont(addmajor.getFont().getSize() + 8f));
adddialogContentPane.add(addmajor);
addmajor.setBounds(new Rectangle(new Point(65, 115), addmajor.getPreferredSize()));
adddialogContentPane.add(addidtext);
addidtext.setBounds(125, 35, 235, 25);
adddialogContentPane.add(addnametext);
addnametext.setBounds(125, 75, 235, 25);
adddialogContentPane.add(addmajortext);
addmajortext.setBounds(125, 115, 235, 25);
//---- confirmbutton ----
confirmbutton.setText("\u786e\u8ba4");
confirmbutton.setFont(confirmbutton.getFont().deriveFont(confirmbutton.getFont().getSize() + 9f));
confirmbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
confirmbuttonMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
adddialogContentPane.add(confirmbutton);
confirmbutton.setBounds(new Rectangle(new Point(180, 160), confirmbutton.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < adddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = adddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = adddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
adddialogContentPane.setMinimumSize(preferredSize);
adddialogContentPane.setPreferredSize(preferredSize);
}
adddialog.setSize(445, 250);
adddialog.setLocationRelativeTo(adddialog.getOwner());
}
//======== existstudentdialog ========
{
existstudentdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
existstudentdialog.setAlwaysOnTop(true);
existstudentdialog.setModal(true);
var existstudentdialogContentPane = existstudentdialog.getContentPane();
existstudentdialogContentPane.setLayout(null);
//---- existstudenttext ----
existstudenttext.setText("\u8be5\u5b66\u751f\u5df2\u5b58\u5728\uff01");
existstudenttext.setFont(existstudenttext.getFont().deriveFont(existstudenttext.getFont().getSize() + 7f));
existstudentdialogContentPane.add(existstudenttext);
existstudenttext.setBounds(new Rectangle(new Point(45, 35), existstudenttext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < existstudentdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = existstudentdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = existstudentdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
existstudentdialogContentPane.setMinimumSize(preferredSize);
existstudentdialogContentPane.setPreferredSize(preferredSize);
}
existstudentdialog.setSize(265, 130);
existstudentdialog.setLocationRelativeTo(existstudentdialog.getOwner());
}
//======== addokdialog ========
{
addokdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addokdialog.setAlwaysOnTop(true);
addokdialog.setModal(true);
var addokdialogContentPane = addokdialog.getContentPane();
addokdialogContentPane.setLayout(null);
//---- addokbutton ----
addokbutton.setText("\u6dfb\u52a0\u6210\u529f");
addokbutton.setFont(addokbutton.getFont().deriveFont(addokbutton.getFont().getSize() + 7f));
addokbutton.setFocusPainted(false);
addokbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
addokbuttonMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
addokdialogContentPane.add(addokbutton);
addokbutton.setBounds(new Rectangle(new Point(30, 35), addokbutton.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < addokdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = addokdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = addokdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
addokdialogContentPane.setMinimumSize(preferredSize);
addokdialogContentPane.setPreferredSize(preferredSize);
}
addokdialog.setSize(185, 130);
addokdialog.setLocationRelativeTo(addokdialog.getOwner());
}
//======== deleteokdialog ========
{
deleteokdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
deleteokdialog.setAlwaysOnTop(true);
deleteokdialog.setModal(true);
var deleteokdialogContentPane = deleteokdialog.getContentPane();
deleteokdialogContentPane.setLayout(null);
//---- deleteokbutton ----
deleteokbutton.setText("\u5220\u9664\u6210\u529f");
deleteokbutton.setFont(deleteokbutton.getFont().deriveFont(deleteokbutton.getFont().getSize() + 7f));
deleteokbutton.setFocusPainted(false);
deleteokbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
deleteokbuttonMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
deleteokdialogContentPane.add(deleteokbutton);
deleteokbutton.setBounds(new Rectangle(new Point(30, 35), deleteokbutton.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < deleteokdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = deleteokdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = deleteokdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
deleteokdialogContentPane.setMinimumSize(preferredSize);
deleteokdialogContentPane.setPreferredSize(preferredSize);
}
deleteokdialog.setSize(185, 130);
deleteokdialog.setLocationRelativeTo(deleteokdialog.getOwner());
}
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
private JLabel systemname;
private JScrollPane title;
private JTable table;
private JButton query;
private JButton add;
private JButton delete;
private JTextField inputidquery;
private JButton exit;
private JTextField inputiddelete;
private JDialog querydialog;
private JLabel getid;
private JLabel getname;
private JLabel getmajor;
private JLabel getidtext;
private JLabel getnametext;
private JLabel getmajortext;
private JDialog nostudentdialog;
private JLabel nostudenttext;
private JDialog adddialog;
private JLabel addid;
private JLabel addname;
private JLabel addmajor;
private JTextField addidtext;
private JTextField addnametext;
private JTextField addmajortext;
private JButton confirmbutton;
private JDialog existstudentdialog;
private JLabel existstudenttext;
private JDialog addokdialog;
private JButton addokbutton;
private JDialog deleteokdialog;
private JButton deleteokbutton;
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
public void studentQuery() throws SQLException {
DefaultTableModel model = (DefaultTableModel) table.getModel();
ResultSet resultSet = StudentSystem.getAllStudent();
while (resultSet.next()) {
model.addRow(new Object[]{resultSet.getString(1), resultSet.getString(2), resultSet.getString(3)});
}
}
public void studentAdd(String idIn, String nameIn, String majorIn) throws SQLException {
if (StudentSystem.contains(idIn)) {
existstudentdialog.setVisible(true);
return;
}
Student student = new Student(idIn, nameIn, majorIn);
StudentSystem.addStudent(student);
}
}
功能
package UI;
import StuInfoManageSystem.UserSystem;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import javax.swing.*;
public class FindPasswdFrame extends JFrame {
public FindPasswdFrame() {
initComponents();
this.setVisible(true);
}
private void exitMouseReleased(MouseEvent e) {
// TODO add your code here
new LoginFrame();
this.dispose();
}
private void confirmMouseReleased(MouseEvent e) throws SQLException {
// TODO add your code here
userRecover(inputusername.getText(), inputpersonid.getText(), inputphonenum.getText(), new String(inputresetpassword.getPassword()), new String(inputpasswrodagain.getPassword()));
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
Title = new JLabel();
usrname = new JLabel();
resetpassword = new JLabel();
inputusername = new JTextField();
inputresetpassword = new JPasswordField();
confirm = new JButton();
personid = new JLabel();
passwordagain = new JLabel();
inputpasswrodagain = new JPasswordField();
inputpersonid = new JTextField();
phonenum = new JLabel();
inputphonenum = new JTextField();
exit = new JButton();
nouserdialog = new JDialog();
nousertext = new JLabel();
errorpersoniddialog = new JDialog();
errorpersonidtext = new JLabel();
errorphonenumdialog = new JDialog();
errorphonenumtext = new JLabel();
differentpassworddialog = new JDialog();
differentpasswordtext = new JLabel();
okdialog = new JDialog();
oktext = new JLabel();
//======== this ========
setFont(new Font(Font.DIALOG, Font.PLAIN, 14));
setAlwaysOnTop(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
var contentPane = getContentPane();
contentPane.setLayout(null);
//---- Title ----
Title.setText("\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf");
Title.setFont(Title.getFont().deriveFont(Title.getFont().getStyle() & ~Font.ITALIC, Title.getFont().getSize() + 15f));
contentPane.add(Title);
Title.setBounds(new Rectangle(new Point(130, 40), Title.getPreferredSize()));
//---- usrname ----
usrname.setText("\u7528\u6237\u540d\uff1a");
usrname.setFont(usrname.getFont().deriveFont(usrname.getFont().getSize() + 6f));
contentPane.add(usrname);
usrname.setBounds(new Rectangle(new Point(70, 95), usrname.getPreferredSize()));
//---- resetpassword ----
resetpassword.setText("\u91cd\u7f6e\u5bc6\u7801\uff1a");
resetpassword.setFont(resetpassword.getFont().deriveFont(resetpassword.getFont().getSize() + 6f));
contentPane.add(resetpassword);
resetpassword.setBounds(new Rectangle(new Point(50, 215), resetpassword.getPreferredSize()));
contentPane.add(inputusername);
inputusername.setBounds(145, 95, 230, 25);
contentPane.add(inputresetpassword);
inputresetpassword.setBounds(145, 215, 230, 25);
//---- confirm ----
confirm.setText("\u786e\u5b9a");
confirm.setFont(confirm.getFont().deriveFont(Font.BOLD, confirm.getFont().getSize() + 6f));
confirm.setFocusPainted(false);
confirm.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
try {
confirmMouseReleased(e);} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
});
contentPane.add(confirm);
confirm.setBounds(new Rectangle(new Point(220, 310), confirm.getPreferredSize()));
//---- personid ----
personid.setText("\u8eab\u4efd\u8bc1\u53f7\uff1a");
personid.setFont(personid.getFont().deriveFont(personid.getFont().getSize() + 6f));
contentPane.add(personid);
personid.setBounds(new Rectangle(new Point(50, 135), personid.getPreferredSize()));
//---- passwordagain ----
passwordagain.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
passwordagain.setFont(passwordagain.getFont().deriveFont(passwordagain.getFont().getSize() + 6f));
contentPane.add(passwordagain);
passwordagain.setBounds(new Rectangle(new Point(50, 255), passwordagain.getPreferredSize()));
contentPane.add(inputpasswrodagain);
inputpasswrodagain.setBounds(145, 255, 230, 25);
contentPane.add(inputpersonid);
inputpersonid.setBounds(145, 135, 230, 25);
//---- phonenum ----
phonenum.setText("\u624b\u673a\u53f7\uff1a");
phonenum.setFont(phonenum.getFont().deriveFont(phonenum.getFont().getSize() + 6f));
contentPane.add(phonenum);
phonenum.setBounds(new Rectangle(new Point(65, 175), phonenum.getPreferredSize()));
contentPane.add(inputphonenum);
inputphonenum.setBounds(145, 175, 230, 25);
//---- exit ----
exit.setText("\u8fd4\u56de");
exit.setFont(exit.getFont().deriveFont(Font.BOLD, exit.getFont().getSize() + 6f));
exit.setFocusPainted(false);
exit.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
exitMouseReleased(e);
}
});
contentPane.add(exit);
exit.setBounds(new Rectangle(new Point(220, 350), exit.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
setSize(520, 435);
setLocationRelativeTo(getOwner());
//======== nouserdialog ========
{
nouserdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
nouserdialog.setAlwaysOnTop(true);
nouserdialog.setModal(true);
var nouserdialogContentPane = nouserdialog.getContentPane();
nouserdialogContentPane.setLayout(null);
//---- nousertext ----
nousertext.setText("\u5f53\u524d\u7528\u6237\u4e0d\u5b58\u5728\uff01\u8bf7\u5148\u6ce8\u518c");
nousertext.setFont(nousertext.getFont().deriveFont(nousertext.getFont().getSize() + 7f));
nouserdialogContentPane.add(nousertext);
nousertext.setBounds(new Rectangle(new Point(45, 35), nousertext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < nouserdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = nouserdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = nouserdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
nouserdialogContentPane.setMinimumSize(preferredSize);
nouserdialogContentPane.setPreferredSize(preferredSize);
}
nouserdialog.setSize(345, 130);
nouserdialog.setLocationRelativeTo(nouserdialog.getOwner());
}
//======== errorpersoniddialog ========
{
errorpersoniddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorpersoniddialog.setAlwaysOnTop(true);
errorpersoniddialog.setModal(true);
var errorpersoniddialogContentPane = errorpersoniddialog.getContentPane();
errorpersoniddialogContentPane.setLayout(null);
//---- errorpersonidtext ----
errorpersonidtext.setText("\u8eab\u4efd\u8bc1\u65e0\u6cd5\u5339\u914d\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errorpersonidtext.setFont(errorpersonidtext.getFont().deriveFont(errorpersonidtext.getFont().getSize() + 7f));
errorpersoniddialogContentPane.add(errorpersonidtext);
errorpersonidtext.setBounds(new Rectangle(new Point(45, 35), errorpersonidtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorpersoniddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorpersoniddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorpersoniddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorpersoniddialogContentPane.setMinimumSize(preferredSize);
errorpersoniddialogContentPane.setPreferredSize(preferredSize);
}
errorpersoniddialog.setSize(345, 130);
errorpersoniddialog.setLocationRelativeTo(errorpersoniddialog.getOwner());
}
//======== errorphonenumdialog ========
{
errorphonenumdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorphonenumdialog.setAlwaysOnTop(true);
errorphonenumdialog.setModal(true);
var errorphonenumdialogContentPane = errorphonenumdialog.getContentPane();
errorphonenumdialogContentPane.setLayout(null);
//---- errorphonenumtext ----
errorphonenumtext.setText("\u624b\u673a\u53f7\u65e0\u6cd5\u5339\u914d\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
errorphonenumtext.setFont(errorphonenumtext.getFont().deriveFont(errorphonenumtext.getFont().getSize() + 7f));
errorphonenumdialogContentPane.add(errorphonenumtext);
errorphonenumtext.setBounds(new Rectangle(new Point(45, 35), errorphonenumtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < errorphonenumdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = errorphonenumdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = errorphonenumdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
errorphonenumdialogContentPane.setMinimumSize(preferredSize);
errorphonenumdialogContentPane.setPreferredSize(preferredSize);
}
errorphonenumdialog.setSize(345, 130);
errorphonenumdialog.setLocationRelativeTo(errorphonenumdialog.getOwner());
}
//======== differentpassworddialog ========
{
differentpassworddialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
differentpassworddialog.setAlwaysOnTop(true);
differentpassworddialog.setModal(true);
var differentpassworddialogContentPane = differentpassworddialog.getContentPane();
differentpassworddialogContentPane.setLayout(null);
//---- differentpasswordtext ----
differentpasswordtext.setText("\u4e24\u6b21\u5bc6\u7801\u4e0d\u4e00\u81f4\uff01\u8bf7\u91cd\u65b0\u8f93\u5165");
differentpasswordtext.setFont(differentpasswordtext.getFont().deriveFont(differentpasswordtext.getFont().getSize() + 7f));
differentpassworddialogContentPane.add(differentpasswordtext);
differentpasswordtext.setBounds(new Rectangle(new Point(45, 35), differentpasswordtext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < differentpassworddialogContentPane.getComponentCount(); i++) {
Rectangle bounds = differentpassworddialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = differentpassworddialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
differentpassworddialogContentPane.setMinimumSize(preferredSize);
differentpassworddialogContentPane.setPreferredSize(preferredSize);
}
differentpassworddialog.setSize(345, 130);
differentpassworddialog.setLocationRelativeTo(differentpassworddialog.getOwner());
}
//======== okdialog ========
{
okdialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
okdialog.setAlwaysOnTop(true);
okdialog.setModal(true);
var okdialogContentPane = okdialog.getContentPane();
okdialogContentPane.setLayout(null);
//---- oktext ----
oktext.setText("\u5bc6\u7801\u91cd\u7f6e\u6210\u529f\uff01\u8bf7\u8fd4\u56de\u767b\u5f55");
oktext.setFont(oktext.getFont().deriveFont(oktext.getFont().getSize() + 7f));
okdialogContentPane.add(oktext);
oktext.setBounds(new Rectangle(new Point(45, 35), oktext.getPreferredSize()));
{
// compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < okdialogContentPane.getComponentCount(); i++) {
Rectangle bounds = okdialogContentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = okdialogContentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
okdialogContentPane.setMinimumSize(preferredSize);
okdialogContentPane.setPreferredSize(preferredSize);
}
okdialog.setSize(345, 130);
okdialog.setLocationRelativeTo(okdialog.getOwner());
}
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
private JLabel Title;
private JLabel usrname;
private JLabel resetpassword;
private JTextField inputusername;
private JPasswordField inputresetpassword;
private JButton confirm;
private JLabel personid;
private JLabel passwordagain;
private JPasswordField inputpasswrodagain;
private JTextField inputpersonid;
private JLabel phonenum;
private JTextField inputphonenum;
private JButton exit;
private JDialog nouserdialog;
private JLabel nousertext;
private JDialog errorpersoniddialog;
private JLabel errorpersonidtext;
private JDialog errorphonenumdialog;
private JLabel errorphonenumtext;
private JDialog differentpassworddialog;
private JLabel differentpasswordtext;
private JDialog okdialog;
private JLabel oktext;
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
public void userRecover(String usernameIn, String personidIn, String phonenumIn, String reset, String resetagain) throws SQLException {
//用户名是否存在
if (!UserSystem.containsUser(usernameIn)) {
nouserdialog.setVisible(true);
return;
}
//验证身份证号和手机号
if (!UserSystem.getUserPersonId(usernameIn).equalsIgnoreCase(personidIn)) {
errorpersoniddialog.setVisible(true);
return;
}
if (!UserSystem.getUserPhoneNum(usernameIn).equals(phonenumIn)) {
errorphonenumdialog.setVisible(true);
return;
}
//两次密码输入一致
if (!resetagain.equals(reset)) {
differentpassworddialog.setVisible(true);
return;
} else {
UserSystem.updateUserPassword(usernameIn, resetagain);
}
UserSystem.updateUserPassword(usernameIn, resetagain);
okdialog.setVisible(true);
}
}
启动入口
package StuInfoManageSystem;
import UI.LoginFrame;
public class Main {
public static void main(String[] args) {
new LoginFrame();
}
}