📄 regist.java
字号:
package Srs;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.net.*;
import Srs.LinkDatabase;
import Srs.MajorSrs;
import java.sql.*;
public class Regist extends JFrame implements ActionListener,ItemListener{
private JComboBox comboBox_3;
private JComboBox comboBox_2;
private JComboBox comboBox_1;
private JComboBox comboBox;
private JPasswordField textField_6;
private JPasswordField textField_5;
private JTextField textField_4;
private JTextField textField_1;
private JTextField textField;
private JButton button;
private JButton button_1;
private JButton button_2;
private String string_sex,string_year,string_month,string_date;
/**
* Launch the application
* @param args
*/
/**
* Create the frame
*/
public Regist(){
super();
this.setLocationRelativeTo(null);
this.init();
}
public void init() {
getContentPane().setLayout(null);
setBounds(100, 100, 500, 375);
this.setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel();
label.setFont(new Font("楷体_GB2312", Font.BOLD, 36));
label.setText("注册界面");
label.setBounds(177, 10, 174, 36);
getContentPane().add(label);
JLabel label_1 = new JLabel();
label_1.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_1.setText("学号:");
label_1.setBounds(100, 78, 66, 18);
getContentPane().add(label_1);
JLabel label_2 = new JLabel();
label_2.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_2.setText("出生日期:");
label_2.setBounds(100, 150, 95, 18);
getContentPane().add(label_2);
JLabel label_3 = new JLabel();
label_3.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_3.setText("登陆密码:");
label_3.setBounds(100, 198, 95, 18);
getContentPane().add(label_3);
JLabel label_4 = new JLabel();
label_4.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_4.setText("姓名:");
label_4.setBounds(100, 102, 66, 18);
getContentPane().add(label_4);
JLabel label_5 = new JLabel();
label_5.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_5.setText("性别:");
label_5.setBounds(100, 126, 66, 18);
getContentPane().add(label_5);
JLabel label_6 = new JLabel();
label_6.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_6.setText("密码确认:");
label_6.setBounds(100, 222, 95, 18);
getContentPane().add(label_6);
JLabel label_7 = new JLabel();
label_7.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_7.setText("家庭住址:");
label_7.setBounds(100, 174, 95, 18);
getContentPane().add(label_7);
textField = new JTextField();
textField.setBounds(222, 79, 215, 22);
getContentPane().add(textField);
textField_1 = new JTextField();
textField_1.setBounds(222, 103, 215, 22);
getContentPane().add(textField_1);
textField_4 = new JTextField();
textField_4.setBounds(222, 175, 215, 22);
getContentPane().add(textField_4);
textField_5 = new JPasswordField();
textField_5.setBounds(222, 199, 215, 22);
getContentPane().add(textField_5);
textField_6 = new JPasswordField();
textField_6.setBounds(222, 223, 215, 22);
getContentPane().add(textField_6);
comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"", "Man", "Woman"}));
comboBox.setBounds(222, 127, 215, 22);
getContentPane().add(comboBox);
comboBox.addItemListener(this);
comboBox_1 = new JComboBox();
comboBox_1.setKeySelectionManager(null);
comboBox_1.setInputVerifier(null);
comboBox_1.setEditor(null);
comboBox_1.setComponentPopupMenu(null);
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998"}));
comboBox_1.setBounds(222, 151, 66, 22);
getContentPane().add(comboBox_1);
comboBox_1.addItemListener(this);
comboBox_2 = new JComboBox();
comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}));
comboBox_2.setBounds(314, 151, 43, 22);
getContentPane().add(comboBox_2);
comboBox_2.addItemListener(this);
comboBox_3 = new JComboBox();
comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}));
comboBox_3.setBounds(378, 151, 43, 22);
getContentPane().add(comboBox_3);
comboBox_3.addItemListener(this);
JLabel label_8 = new JLabel();
label_8.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_8.setText("年");
label_8.setBounds(294, 151, 19, 22);
getContentPane().add(label_8);
JLabel label_9 = new JLabel();
label_9.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_9.setText("月");
label_9.setBounds(357, 151, 19, 22);
getContentPane().add(label_9);
JLabel label_10 = new JLabel();
label_10.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_10.setText("日");
label_10.setBounds(421, 151, 19, 22);
getContentPane().add(label_10);
JLabel label_11 = new JLabel();
label_11.setForeground(new Color(255, 0, 0));
label_11.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
label_11.setText("注意:学号即为登陆用户名");
label_11.setBounds(100, 258, 337, 26);
getContentPane().add(label_11);
button = new JButton();
button.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
button.setText("确认");
button.setBounds(159, 290, 86, 28);
getContentPane().add(button);
button.addActionListener(this);
button_1 = new JButton();
button_1.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
button_1.setText("取消");
button_1.setBounds(301, 290, 86, 28);
getContentPane().add(button_1);
button_1.addActionListener(this);
final JLabel label_12 = new JLabel();
label_12.setForeground(new Color(255, 0, 0));
label_12.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_12.setText("*");
label_12.setBounds(28, 81, 66, 18);
getContentPane().add(label_12);
final JLabel label_13 = new JLabel();
label_13.setForeground(new Color(255, 0, 0));
label_13.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_13.setText("*");
label_13.setBounds(28, 102, 66, 18);
getContentPane().add(label_13);
final JLabel label_14 = new JLabel();
label_14.setForeground(new Color(255, 0, 0));
label_14.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_14.setText("*");
label_14.setBounds(28, 126, 66, 18);
getContentPane().add(label_14);
final JLabel label_15 = new JLabel();
label_15.setForeground(new Color(255, 0, 0));
label_15.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_15.setText("*");
label_15.setBounds(28, 150, 66, 18);
getContentPane().add(label_15);
final JLabel label_16 = new JLabel();
label_16.setForeground(new Color(255, 0, 0));
label_16.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_16.setText("*");
label_16.setBounds(28, 201, 66, 18);
getContentPane().add(label_16);
final JLabel label_17 = new JLabel();
label_17.setForeground(new Color(255, 0, 0));
label_17.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
label_17.setText("*");
label_17.setBounds(28, 222, 66, 18);
getContentPane().add(label_17);
button_2 = new JButton();
button_2.setText("返回");
button_2.setBounds(421, 315, 61, 18);
getContentPane().add(button_2);
button_2.addActionListener(this);
//
}
public String getId(){
return textField.getText();
}
public String getName(){
return textField_1.getText();
}
public String getAddress(){
return textField_4.getText();
}
public char[] getPassword(){
return textField_5.getPassword();
}
public char[] getRpassword(){
return textField_6.getPassword();
}
public void itemStateChanged(ItemEvent e){
if(e.getSource() == comboBox){
string_sex = ((String)e.getItem());
}
else if(e.getSource() == comboBox_1){
string_year = ((String)e.getItem());
}
else if(e.getSource() == comboBox_2){
string_month = ((String)e.getItem());
}
else if(e.getSource() == comboBox_3){
string_date = ((String)e.getItem());
}
}
public String getstring_sex(){
return string_sex;
}
public String getstring_year(){
return string_year;
}
public String getstring_month(){
return string_month;
}
public String getstring_date(){
return string_date;
}
public String quotate(String content){
return "'"+content+"'";
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == button){
if(this.getId()==null||this.getName() == null||
string_sex == null|| string_year == null||
string_month == null||string_date == null||
this.getPassword() == null||this.getRpassword() == null){
JOptionPane newone = new JOptionPane();
newone.showMessageDialog(null, "‘*’为必填项,请将信息补充完整");
}
else if(!String.valueOf(this.getPassword()).equalsIgnoreCase(String.valueOf(this.getRpassword()))){
JOptionPane newone = new JOptionPane();
newone.showMessageDialog(null, "请确认前后密码输入的一致性");
}
else{
try{
LinkDatabase linkDatabase = new LinkDatabase();
Connection connection = linkDatabase.getlink();
Statement statement = connection.createStatement();
String sql = "insert into students values " +
"("+quotate(this.getId())+","+quotate(String.valueOf(this.getPassword()))+","
+quotate(this.getName())+","+quotate(string_sex)+
","+quotate(string_year+"-"+string_month+"-"
+string_date)+","+quotate(this.getAddress())+")";
String sql_1 = "create table "+this.getId()+
"(课程编号 char(10) NOT NULL," +
"课程名称 char(10) NOT NULL," +
"课程说明 char(100) NOT NULL," +
"授课教师 char(10) NOT NULL," +
"教师信息 char(100) NOT NULL," +
"上课时间 char(30) NOT NULL," +
"上课地点 char(30) NOT NULL," +
"PRIMARY KEY(课程编号))";
statement.execute(sql);
statement.execute(sql_1);
JOptionPane newone = new JOptionPane();
newone.showMessageDialog(null, "注册成功");
}catch(SQLException e1){
e1.printStackTrace();
}
}
}
else if(e.getSource() == button_1){
textField.setText("");
textField_1.setText("");
textField_4.setText("");
textField_5.setText("");
textField_6.setText("");
}
else if(e.getSource() == button_2){
this.setVisible(false);
MajorSrs majorSrs = new MajorSrs();
majorSrs.setVisible(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -