⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stuadd.java~9~

📁 java语言做的教务管理系统
💻 JAVA~9~
字号:
package java_教务管理系统;

import java.awt.*;

import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.awt.Font;

/**
 * <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();
        } 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(105, 128, 72, 27));
        txtstuno.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuno.setBounds(new Rectangle(185, 128, 137, 27));
        jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel2.setText("姓名:");
        jLabel2.setBounds(new Rectangle(445, 124, 85, 29));
        txtstuname.setBounds(new Rectangle(536, 128, 175, 27));
        jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel3.setText("性别:");
        jLabel3.setBounds(new Rectangle(105, 171, 84, 29));
        jLabel4.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel4.setText("班级编号:");
        jLabel4.setBounds(new Rectangle(257, 212, 111, 25));
        txtstuclassno.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuclassno.setBounds(new Rectangle(437, 210, 137, 27));
        jLabel5.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel5.setText("身份证号码:");
        jLabel5.setBounds(new Rectangle(363, 173, 144, 27));
        txtstuidcard.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuidcard.setBounds(new Rectangle(494, 167, 217, 30));
        jLabel6.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel6.setText("出生日期:");
        jLabel6.setBounds(new Rectangle(137, 255, 109, 31));
        jLabel7.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel7.setText("年");
        jLabel7.setBounds(new Rectangle(344, 253, 32, 31));
        jLabel8.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel8.setText("月");
        jLabel8.setBounds(new Rectangle(471, 247, 33, 39));
        jLabel9.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel9.setText("日");
        jLabel9.setBounds(new Rectangle(596, 250, 32, 32));
        jLabel10.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel10.setText("家庭地址:");
        jLabel10.setBounds(new Rectangle(66, 297, 104, 30));
        txtstuaddress.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuaddress.setBounds(new Rectangle(182, 297, 529, 29));
        jLabel11.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel11.setText("联系电话:");
        jLabel11.setBounds(new Rectangle(66, 340, 114, 33));
        txtstuphoto.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuphoto.setBounds(new Rectangle(182, 344, 192, 27));
        jLabel12.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel12.setText("毕业学校:");
        jLabel12.setBounds(new Rectangle(392, 341, 119, 33));
        txtstuschool.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        txtstuschool.setBounds(new Rectangle(494, 344, 217, 27));
        jLabel13.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel13.setText("最高学历:");
        jLabel13.setBounds(new Rectangle(334, 384, 104, 39));
        jLabel14.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel14.setText("状态:");
        jLabel14.setBounds(new Rectangle(96, 385, 77, 37));
        jLabel15.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel15.setText("备注:");
        jLabel15.setBounds(new Rectangle(93, 439, 98, 37));
        cbostuappearance.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostuappearance.setBounds(new Rectangle(182, 388, 94, 28));
        cbostubirthdaydate.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostubirthdaydate.setBounds(new Rectangle(510, 250, 64, 31));
        cbostubirthdaymonth.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostubirthdaymonth.setBounds(new Rectangle(381, 250, 69, 31));
        cbostubirthdayyear.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostubirthdayyear.setBounds(new Rectangle(254, 251, 79, 30));
        cbostusex.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostusex.setBounds(new Rectangle(184, 169, 70, 29));
        txasturemarks.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
        txasturemarks.setBounds(new Rectangle(182, 435, 529, 78));
        btnstuadd.setBounds(new Rectangle(194, 535, 159, 43));
        btnstuadd.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        btnstuadd.setText("添加学生");
        btnstuadd.addActionListener(new stuadd_btnstuadd_actionAdapter(this));
        btnexit.setBounds(new Rectangle(534, 535, 158, 43));
        btnexit.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        btnexit.setText("退出添加");
        cbostubackground.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        cbostubackground.setBounds(new Rectangle(460, 387, 99, 30));
        jLabel16.setFont(new java.awt.Font("华文彩云", Font.PLAIN, 60));
        jLabel16.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel16.setText("添加学生");
        jLabel16.setBounds(new Rectangle(33, 4, 772, 106));
        this.add(jLabel16);
        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(txtstuclassno);
        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(btnexit);
        this.add(btnstuadd);
    }

    //性别
    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();
    JTextField txtstuclassno = new JTextField();
    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);
    JLabel jLabel16 = new JLabel();
    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;
            }
            if (this.txtstuclassno.getText().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.txtstuclassno.getText());
            //身份证
            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, "添加失败!");
        }
    }
}


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 + -