📄 stuadd.java~17~
字号:
package java_教务管理系统;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Font;
import java.awt.Rectangle;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class stuadd extends JPanel {
public stuadd() {
try {
jbInit();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(
"jdbc:odbc:studer");
PreparedStatement sql = conn.prepareStatement(
"select classno from class");
ResultSet i = sql.executeQuery();
while(i.next()){
this.cboclassno.addItem(i.getString(1));
}
} catch (Exception ex) {
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel1.setText("学号:");
jLabel1.setBounds(new Rectangle(104, 41, 72, 27));
txtstuno.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuno.setBounds(new Rectangle(184, 41, 137, 27));
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel2.setText("姓名:");
jLabel2.setBounds(new Rectangle(444, 37, 85, 29));
txtstuname.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuname.setBounds(new Rectangle(535, 41, 175, 27));
jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel3.setText("性别:");
jLabel3.setBounds(new Rectangle(104, 84, 84, 29));
jLabel4.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel4.setText("班级编号:");
jLabel4.setBounds(new Rectangle(256, 125, 111, 25));
jLabel5.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel5.setText("身份证号码:");
jLabel5.setBounds(new Rectangle(362, 86, 144, 27));
txtstuidcard.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuidcard.setBounds(new Rectangle(493, 80, 217, 30));
jLabel6.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel6.setText("出生日期:");
jLabel6.setBounds(new Rectangle(136, 168, 109, 31));
jLabel7.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel7.setText("年");
jLabel7.setBounds(new Rectangle(343, 166, 32, 31));
jLabel8.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel8.setText("月");
jLabel8.setBounds(new Rectangle(470, 160, 33, 39));
jLabel9.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel9.setText("日");
jLabel9.setBounds(new Rectangle(595, 163, 32, 32));
jLabel10.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel10.setText("家庭地址:");
jLabel10.setBounds(new Rectangle(65, 210, 104, 30));
txtstuaddress.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuaddress.setBounds(new Rectangle(181, 210, 529, 29));
jLabel11.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel11.setText("联系电话:");
jLabel11.setBounds(new Rectangle(65, 253, 114, 33));
txtstuphoto.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuphoto.setBounds(new Rectangle(181, 257, 192, 27));
jLabel12.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel12.setText("毕业学校:");
jLabel12.setBounds(new Rectangle(391, 254, 119, 33));
txtstuschool.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtstuschool.setBounds(new Rectangle(493, 257, 217, 27));
jLabel13.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel13.setText("最高学历:");
jLabel13.setBounds(new Rectangle(333, 297, 104, 39));
jLabel14.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel14.setText("状态:");
jLabel14.setBounds(new Rectangle(95, 298, 77, 37));
jLabel15.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel15.setText("备注:");
jLabel15.setBounds(new Rectangle(92, 352, 98, 37));
cbostuappearance.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostuappearance.setBounds(new Rectangle(181, 301, 94, 28));
cbostubirthdaydate.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostubirthdaydate.setBounds(new Rectangle(509, 163, 64, 31));
cbostubirthdaymonth.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostubirthdaymonth.setBounds(new Rectangle(380, 163, 69, 31));
cbostubirthdayyear.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostubirthdayyear.setBounds(new Rectangle(253, 164, 79, 30));
cbostusex.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostusex.setBounds(new Rectangle(183, 82, 70, 29));
txasturemarks.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
txasturemarks.setBounds(new Rectangle(181, 348, 529, 78));
btnstuadd.setBounds(new Rectangle(357, 441, 113, 33));
btnstuadd.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnstuadd.setText("添加学生");
btnstuadd.addActionListener(new stuadd_btnstuadd_actionAdapter(this));
btnexit.setBounds(new Rectangle(475, 441, 113, 33));
btnexit.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnexit.setText("退出添加");
cbostubackground.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbostubackground.setBounds(new Rectangle(459, 300, 99, 30));
cboclassno.setBounds(new Rectangle(385, 124, 122, 27));
btnok.setBounds(new Rectangle(239, 441, 113, 33));
btnok.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnok.setText("检测编号");
btnok.addActionListener(new stuadd_btnok_actionAdapter(this));
this.add(cbostubirthdaymonth);
this.add(txtstuno);
this.add(jLabel1);
this.add(jLabel3);
this.add(cbostusex);
this.add(jLabel5);
this.add(jLabel2);
this.add(txtstuname);
this.add(txtstuidcard);
this.add(jLabel4);
this.add(cbostubirthdayyear);
this.add(jLabel6);
this.add(jLabel7);
this.add(jLabel8);
this.add(cbostubirthdaydate);
this.add(jLabel9);
this.add(txtstuaddress);
this.add(jLabel10);
this.add(jLabel11);
this.add(txtstuphoto);
this.add(jLabel12);
this.add(txtstuschool);
this.add(cbostubackground);
this.add(jLabel13);
this.add(cbostuappearance);
this.add(jLabel14);
this.add(jLabel15);
this.add(txasturemarks);
this.add(cboclassno);
this.add(btnstuadd);
this.add(btnexit);
this.add(btnok);
}
//性别
String stusex[] = {"男", "女"};
//出生时间(年)
String stubirthdayyear[] = {"", "1981", "1982", "1983", "1984", "1985",
"1986", "1987", "1988", "1989", "1990", "1991",
"1992", "1993"};
//出生时间(月)
String stubirthdaymonth[] = {"", "01", "02", "03", "04", "05", "06", "07",
"08",
"09",
"10", "11", "12"};
//出生时间(日)
String stubirthdaydate[] = {"", "01", "02", "03", "04", "05", "06", "07",
"08",
"09",
"10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25",
"26", "27", "28", "29", "30", "31"};
//状态
String stuappearance[] = {"在读", "休学", "退学", "转班"};
JLabel jLabel1 = new JLabel();
JTextField txtstuno = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField txtstuname = new JTextField();
JLabel jLabel3 = new JLabel();
JComboBox cbostusex = new JComboBox(stusex);
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField txtstuidcard = new JTextField();
JLabel jLabel6 = new JLabel();
JComboBox cbostubirthdayyear = new JComboBox(stubirthdayyear);
JLabel jLabel7 = new JLabel();
JComboBox cbostubirthdaymonth = new JComboBox(stubirthdaymonth);
JLabel jLabel8 = new JLabel();
JComboBox cbostubirthdaydate = new JComboBox(stubirthdaydate);
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JTextField txtstuaddress = new JTextField();
JLabel jLabel11 = new JLabel();
JTextField txtstuphoto = new JTextField();
JLabel jLabel12 = new JLabel();
JTextField txtstuschool = new JTextField();
JLabel jLabel13 = new JLabel();
JLabel jLabel14 = new JLabel();
JComboBox cbostuappearance = new JComboBox(stuappearance);
JLabel jLabel15 = new JLabel();
JTextArea txasturemarks = new JTextArea();
JButton btnstuadd = new JButton();
JButton btnexit = new JButton();
String stubackground[] = {"", "初中", "高中", "大专", "本科", "研究生", "博士"};
JComboBox cbostubackground = new JComboBox(stubackground);
JComboBox cboclassno = new JComboBox();
JButton btnok = new JButton();
public void btnstuadd_actionPerformed(ActionEvent e) {
try {
//状态
String stuappearance = this.cbostuappearance.getSelectedItem().
toString();
//性别
String stusex = this.cbostusex.getSelectedItem().toString();
//出生日期
String beginstimename =
this.cbostubirthdayyear.getSelectedItem().toString() + "-" +
this.cbostubirthdaymonth.getSelectedItem().toString() + "-" +
this.cbostubirthdaydate.getSelectedItem().toString() + " ";
if (this.txtstuno.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入学生编号");
return;
}
if (this.txtstuname.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入姓名");
return;
}
if (stusex.equals("")) {
JOptionPane.showMessageDialog(this, "请选择性别");
return;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:studer");
PreparedStatement sql = conn.prepareStatement(
"insert into stu (stuno,stuname,stusex,stuclassno,stuidcard,stubirthday,stuaddress,stuphoto,stuschool,stubackground,stuappearance,sturemarks) values(?,?,?,?,?,?,?,?,?,?,?,?)");
//学号
sql.setString(1, this.txtstuno.getText());
//姓名
sql.setString(2, this.txtstuname.getText());
//性别
sql.setString(3, stusex);
//班级编号
sql.setString(4, this.cboclassno.getSelectedItem().toString());
//身份证
sql.setString(5, this.txtstuidcard.getText());
//出生年月
sql.setString(6, beginstimename);
//家庭地址
sql.setString(7, this.txtstuaddress.getText());
//联系电话
sql.setString(8, this.txtstuphoto.getText());
//毕业学校
sql.setString(9, this.txtstuschool.getText());
//最高学历
sql.setString(10, this.cbostubackground.getSelectedItem().toString());
//状态
sql.setString(11, stuappearance);
//备注
sql.setString(12, this.txasturemarks.getText());
int row = sql.executeUpdate();
if (row > 0) {
JOptionPane.showMessageDialog(this, "添加成功!");
} else {
JOptionPane.showMessageDialog(this, "添加失败!");
}
sql.close();
conn.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "添加失败!");
}
}
public void btnok_actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection(
"jdbc:odbc:studer");
String daima =
"select useid from go where useid = '" + this.txtstuno.getText() +
"'";
PreparedStatement sql = nod.prepareStatement(
daima);
ResultSet i = sql.executeQuery();
String no = this.txtstuno.getText();
if (i.next()) {
if (i.getString(1).equals(no)) {
JOptionPane.showMessageDialog(this, "重复编号");
}
} else {
JOptionPane.showMessageDialog(this, "可用编号");
}
i.close();
sql.close();
nod.close();
} catch (Exception ex) {
}
}
}
class stuadd_btnok_actionAdapter implements ActionListener {
private stuadd adaptee;
stuadd_btnok_actionAdapter(stuadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnok_actionPerformed(e);
}
}
class stuadd_btnstuadd_actionAdapter implements ActionListener {
private stuadd adaptee;
stuadd_btnstuadd_actionAdapter(stuadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnstuadd_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -