1 Star 0 Fork 0

数据库实验小组/吴迪

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
User_Signup.java 8.59 KB
一键复制 编辑 原始数据 按行查看 历史
package Testv1;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class User_Signup extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
User_Signup frame = new User_Signup();
frame.setVisible(true);
} catch (Exception var2) {
var2.printStackTrace();
}
}
});
}
public User_Signup() {
this.setDefaultCloseOperation(3);
this.setBounds(100, 100, 450, 500);
this.contentPane = new JPanel();
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
this.setContentPane(this.contentPane);
this.contentPane.setLayout((LayoutManager) null);
JLabel lblNewLabel = new JLabel("读者注册");
lblNewLabel.setFont(new Font("宋体", 0, 22));
lblNewLabel.setBounds(170, 10, 115, 36);
this.contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("借书证号:");
lblNewLabel_1.setFont(new Font("宋体", 0, 14));
lblNewLabel_1.setBounds(44, 64, 84, 36);
this.contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("密码:");
lblNewLabel_2.setFont(new Font("宋体", 0, 14));
lblNewLabel_2.setBounds(59, 123, 84, 15);
this.contentPane.add(lblNewLabel_2);
this.textField = new JTextField();
this.textField.setBounds(138, 72, 184, 21);
this.contentPane.add(this.textField);
this.textField.setColumns(10);
JButton btnNewButton = new JButton("返回");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
User_Signup.this.setVisible(false);
new LogInPage();
}
});
btnNewButton.setBounds(309, 350, 93, 23);
this.contentPane.add(btnNewButton);
this.passwordField = new JPasswordField();
this.passwordField.setBounds(138, 123, 184, 21);
this.contentPane.add(this.passwordField);
final JLabel fail = new JLabel("借书证号已存在");
fail.setForeground(Color.RED);
fail.setBounds(340, 117, 198, 24);
this.contentPane.add(fail);
fail.setVisible(false);
final JLabel success = new JLabel("注册成功!");
success.setForeground(Color.red);
success.setBounds(191, 330, 84, 15);
this.contentPane.add(success);
success.setVisible(false);
final JLabel empty = new JLabel("信息不能为空!");
empty.setForeground(Color.red);
empty.setBounds(191, 330, 84, 15);
this.contentPane.add(empty);
empty.setVisible(false);
final JLabel sexcheck = new JLabel("填入男或女!");
sexcheck.setForeground(Color.red);
sexcheck.setForeground(Color.red);
sexcheck.setBounds(138, 220, 184, 12);
this.contentPane.add(sexcheck);
sexcheck.setVisible(false);
JLabel lblNewLabel_4 = new JLabel("姓名:");
lblNewLabel_4.setFont(new Font("宋体", 0, 14));
lblNewLabel_4.setBounds(59, 160, 84, 15);
this.contentPane.add(lblNewLabel_4);
JTextField name = new JTextField();
name.setBounds(138, 160, 184, 21);
this.contentPane.add(name);
JLabel lblNewLabel_5 = new JLabel("性别:");
lblNewLabel_5.setFont(new Font("宋体", 0, 14));
lblNewLabel_5.setBounds(59, 197, 84, 15);
this.contentPane.add(lblNewLabel_5);
JTextField sex= new JTextField();
sex.setBounds(138, 197, 184, 21);
this.contentPane.add(sex);
JLabel lblNewLabel_6 = new JLabel("联系电话:");
lblNewLabel_6.setFont(new Font("宋体", 0, 14));
lblNewLabel_6.setBounds(59, 234, 84, 15);
this.contentPane.add(lblNewLabel_6);
JTextField phone= new JTextField();
phone.setBounds(138, 234, 184, 21);
this.contentPane.add(phone);
JLabel lblNewLabel_7 = new JLabel("职业:");
lblNewLabel_7.setFont(new Font("宋体", 0, 14));
lblNewLabel_7.setBounds(59, 271, 84, 15);
this.contentPane.add(lblNewLabel_7);
JTextField dept= new JTextField();
dept.setBounds(138, 271, 184, 21);
this.contentPane.add(dept);
JLabel lblNewLabel_8 = new JLabel("所在单位:");
lblNewLabel_8.setFont(new Font("宋体", 0, 14));
lblNewLabel_8.setBounds(59, 308, 84, 15);
this.contentPane.add(lblNewLabel_8);
JTextField department= new JTextField();
department.setBounds(138, 308, 184, 21);
this.contentPane.add(department);
JButton btnNewButton_1 = new JButton("注册");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int exist=0;
int isempty=0;
int sexcorrect=0;
String password = new String(User_Signup.this.passwordField.getPassword());
String account = User_Signup.this.textField.getText();
String Name= name.getText();
String Sex= sex.getText();
String Phone= phone.getText();
String Dept= dept.getText();
String Department= department.getText();
String dbURL = "jdbc:mysql://localhost:3306/librarymanagement";
String userName = "root";
String userPwd = "wu200213";
Connection dbConn = null;
String sql = "select 借书证号,密码 from 借书者";
success.setVisible(false);
fail.setVisible(false);
empty.setVisible(false);
sexcheck.setVisible(false);
try {
Statement state = null;
Class.forName("com.mysql.cj.jdbc.Driver");
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
state = dbConn.createStatement();
ResultSet rs = state.executeQuery(sql);
while (rs.next()) {
if(account.equals("") || Name.equals("")||Sex.equals("")||Phone.equals("")||Dept.equals("")
||Department.equals("")||password.equals(""))
{
isempty=1;
empty.setVisible(true);
break;
}
if (account.equals(rs.getString(1))) {
fail.setVisible(true);
exist=1;
break;
}
}
if(Sex.equals("男")||Sex.equals("女")){
sexcheck.setVisible(false);
sexcorrect=1;
}
else if(isempty==0){
sexcheck.setVisible(true);
}
if(exist==0&&isempty==0&&sexcorrect==1)
{
PreparedStatement pst = null;
pst = dbConn.prepareStatement("insert into 借书者 values(?,?,?,?,?,?,?)");
pst.setString(1, account);
pst.setString(2, Name);
pst.setString(3, Sex);
pst.setString(4, Phone);
pst.setString(5, Dept);
pst.setString(6, Department);
pst.setString(7, password);
pst.addBatch();
pst.executeBatch();
success.setVisible(true);
}
dbConn.close();
} catch (SQLException var14) {
var14.printStackTrace();
} catch (ClassNotFoundException var15) {
var15.printStackTrace();
}
}
});
btnNewButton_1.setBounds(8, 350, 93, 23);
this.contentPane.add(btnNewButton_1);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shujuku_1/database-experiment-6.3.git
git@gitee.com:shujuku_1/database-experiment-6.3.git
shujuku_1
database-experiment-6.3
吴迪
master

搜索帮助