JAVA學(xué)生信息管理系統(tǒng)源碼
精選優(yōu)質(zhì)文檔-傾情為你奉上/ AddStuInfo.javapackage com.main;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JOptionPane;import com.bean.Student;import com.dao.StudentDao;import com.db.DB;import com.main.DelteStudent.delAction;public class AddStuInfo extends JFrame StudentDao studao = new StudentDao();DB db = new DB();Connection conn = db.getConnection();JTextField snoText = null;JTextField snameText = null;JComboBox sexcom = null;JTextField ageText = null;JComboBox classcom = null;JComboBox departcom = null;public void init() / 窗體設(shè)計(jì)this.setLayout(null);this.setTitle("學(xué)生信息管理系統(tǒng)");this.setSize(500, 400);JLabel title = new JLabel("學(xué)生信息維護(hù)模塊-錄入數(shù)據(jù)");title.setBounds(180, 20, 200, 30);this.add(title);JLabel snoLabel = new JLabel("學(xué)號");snoText = new JTextField();snoLabel.setBounds(20, 60, 40, 25);snoText.setBounds(60, 60, 120, 25);this.add(snoLabel);this.add(snoText);JLabel snameLabel = new JLabel("姓名");snameText = new JTextField();snameLabel.setBounds(220, 60, 40, 25);snameText.setBounds(260, 60, 120, 25);this.add(snameLabel);this.add(snameText);JLabel sexlabel = new JLabel("性別");String sex = "男", "女" ;sexcom = new JComboBox(sex);sexlabel.setBounds(20, 90, 40, 25);sexcom.setBounds(60, 90, 120, 25);this.add(sexlabel);this.add(sexcom);JLabel ageLabel = new JLabel("年齡");ageText = new JTextField();ageLabel.setBounds(220, 90, 40, 25);ageText.setBounds(260, 90, 120, 25);this.add(ageLabel);this.add(ageText);JLabel classlabel = new JLabel("班級");String classes = "信息081", "信息082", "物流081" ;classcom = new JComboBox(classes);classlabel.setBounds(20, 120, 40, 25);classcom.setBounds(60, 120, 120, 25);this.add(classlabel);this.add(classcom);JLabel departlabel = new JLabel("學(xué)院");String depart = "造紙", "理學(xué)院", "機(jī)電學(xué)院" ;departcom = new JComboBox(depart);departlabel.setBounds(220, 120, 40, 25);departcom.setBounds(260, 120, 120, 25);this.add(departlabel);this.add(departcom);/ 錄入數(shù)據(jù)JButton addbtn = new JButton("錄入");addbtn.setBounds(150, 180, 60, 30);addbtn.addActionListener(new addAction();this.add(addbtn);/ 返回JButton backbtn = new JButton("返回");backbtn.setBounds(230, 180, 60, 30);backbtn.addActionListener(new BackAction ();this.add(backbtn);this.setLocationRelativeTo(null); / 使窗體居中this.setResizable(false);/ 固定窗體大小this.setVisible(true); / 設(shè)置窗體可見/this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / 窗體關(guān)閉時(shí),程序結(jié)束/ 獲取文本框或選擇框的值public Student getStudent() Student stu = new Student();String sno = snoText.getText(); / 獲取輸入的學(xué)號String sname = snameText.getText(); / 獲取姓名String sex = (String) sexcom.getSelectedItem();/ 獲取性別int age = Integer.parseInt(ageText.getText().trim(); / 獲取年齡String className = (String) classcom.getSelectedItem(); / 獲取班級String depart = (String) departcom.getSelectedItem(); / 獲取學(xué)院/ 封裝信息stu.setSno(sno);stu.setName(sname);stu.setSex(sex);stu.setAge(age);stu.setClassName(className);stu.setDepart(depart);return stu;public static void main(String args) AddStudent addstu = new AddStudent();addstu.init();/ 錄入的監(jiān)聽器class addAction implements ActionListener public void actionPerformed(ActionEvent e) Student stu = getStudent();boolean b = studao.save(stu, conn);if (b) JOptionPane.showMessageDialog(null, "數(shù)據(jù)錄入成功!"); else JOptionPane.showMessageDialog(null, "學(xué)號已存在,數(shù)據(jù)錄入失?。?quot;);class BackAction implements ActionListenerpublic void actionPerformed(ActionEvent e) MainFrame m=new MainFrame (); m.init();/DelStuInfo.javapackage com.main;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.SQLException;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import com.bean.Student;import com.dao.StudentDao;import com.db.DB;import com.main.AddStudent.BackAction;/刪除學(xué)生信息public class DelStuInfo extends JFrame StudentDao studao = new StudentDao();DB db = new DB();Connection conn = db.getConnection();JComboBox snocom = null;public void init() / 窗體設(shè)計(jì)this.setLayout(null);this.setTitle("學(xué)生信息管理系統(tǒng)");this.setSize(500, 400);JLabel title = new JLabel("學(xué)生信息維護(hù)模塊-刪除數(shù)據(jù)");title.setBounds(180, 20, 200, 30);this.add(title);/ 選擇學(xué)號JLabel snoLabel = new JLabel("請選擇要?jiǎng)h除學(xué)生信息的學(xué)號");snoLabel.setBounds(20, 60, 200,25);this.add(snoLabel);try Vector vec = studao.getSno();snocom = new JComboBox(vec); / 將數(shù)據(jù)庫里的學(xué)號信息裝入下拉框中snocom.setBounds(30, 90, 150, 25); catch (SQLException e) e.printStackTrace();this.add(snocom);/ 刪除數(shù)據(jù)JButton delbtn = new JButton("刪除");delbtn.setBounds(100, 180, 60, 30);delbtn.addActionListener(new delAction();this.add(delbtn);/ 返回JButton backbtn = new JButton("返回");backbtn.setBounds(180, 180, 60, 30);backbtn.addActionListener(new BackAction ();this.add(backbtn);this.setLocationRelativeTo(null); / 使窗體居中this.setResizable(false);/ 固定窗體大小this.setVisible(true); / 設(shè)置窗體可見/this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / 窗體關(guān)閉時(shí),程序結(jié)束public static void main(String args) DelteStudent delstu = new DelteStudent();delstu.init();/ 刪除的監(jiān)聽器class delAction implements ActionListener public void actionPerformed(ActionEvent e) String delsno = (String) snocom.getSelectedItem();boolean b = studao.delete(delsno, conn);if (b) JOptionPane.showMessageDialog(null, "刪除錄入成功!"); else JOptionPane.showMessageDialog(null, "刪除錄入失??!");class BackAction implements ActionListenerpublic void actionPerformed(ActionEvent e) MainFrame m=new MainFrame (); m.init();package com.main;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.SQLException;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JOptionPane;import com.bean.Student;import com.dao.StudentDao;import com.db.DB;import com.main.AddStudent.BackAction;import com.main.DelteStudent.delAction;public class EditFrame extends JFrame StudentDao studao = new StudentDao();DB db = new DB();Connection conn = db.getConnection();JTextField snameText = null;JComboBox sexcom = null;JTextField ageText = null;JComboBox classcom = null;JComboBox departcom = null;JComboBox snocom = null;public void init() / 窗體設(shè)計(jì)this.setLayout(null);this.setTitle("學(xué)生信息管理系統(tǒng)");this.setSize(500, 400);JLabel title = new JLabel("學(xué)生信息維護(hù)模塊-修改數(shù)據(jù)");title.setBounds(180, 20, 200, 30);this.add(title);JLabel snoLabel = new JLabel("學(xué)號");snoLabel.setBounds(20, 60, 40, 25);this.add(snoLabel);try Vector vec = studao.getSno();snocom = new JComboBox(vec); / 將數(shù)據(jù)庫里的學(xué)號信息裝入下拉框中snocom.setBounds(60, 60, 120, 25); catch (SQLException e) e.printStackTrace();this.add(snocom);JLabel snameLabel = new JLabel("姓名");snameText = new JTextField();snameLabel.setBounds(220, 60, 40, 25);snameText.setBounds(260, 60, 120, 25);this.add(snameLabel);this.add(snameText);JLabel sexlabel = new JLabel("性別");String sex = "男", "女" ;sexcom = new JComboBox(sex);sexlabel.setBounds(20, 90, 40, 25);sexcom.setBounds(60, 90, 120, 25);this.add(sexlabel);this.add(sexcom);JLabel ageLabel = new JLabel("年齡");ageText = new JTextField();ageLabel.setBounds(220, 90, 40, 25);ageText.setBounds(260, 90, 120, 25);this.add(ageLabel);this.add(ageText);JLabel classlabel = new JLabel("班級");String classes = "信息081", "信息082", "物流081" ;classcom = new JComboBox(classes);classlabel.setBounds(20, 120, 40, 25);classcom.setBounds(60, 120, 120, 25);this.add(classlabel);this.add(classcom);JLabel departlabel = new JLabel("學(xué)院");String depart = "造紙", "理學(xué)院", "機(jī)電學(xué)院" ;departcom = new JComboBox(depart);departlabel.setBounds(220, 120, 40, 25);departcom.setBounds(260, 120, 120, 25);this.add(departlabel);this.add(departcom);/ 修改JButton editbtn = new JButton("修改");editbtn.setBounds(150, 180, 60, 30);editbtn.addActionListener(new editAction();this.add(editbtn);/ 返回JButton backbtn = new JButton("返回");backbtn.setBounds(220, 180, 60, 30);backbtn.addActionListener(new BackAction ();this.add(backbtn);this.setLocationRelativeTo(null); / 使窗體居中this.setResizable(false);/ 固定窗體大小this.setVisible(true); / 設(shè)置窗體可見/ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / 窗體關(guān)閉時(shí),程序結(jié)束/ 獲取文本框或選擇框的值public Student getStudent() Student stu = new Student();String sno = (String) snocom.getSelectedItem(); / 獲取輸入的學(xué)號String sname = snameText.getText(); / 獲取姓名String sex = (String) sexcom.getSelectedItem();/ 獲取性別int age = Integer.parseInt(ageText.getText().trim(); / 獲取年齡String className = (String) classcom.getSelectedItem(); / 獲取班級String depart = (String) departcom.getSelectedItem(); / 獲取學(xué)院/ 封裝信息stu.setSno(sno);stu.setName(sname);stu.setSex(sex);stu.setAge(age);stu.setClassName(className);stu.setDepart(depart);return stu;public static void main(String args) EditFrame editstu = new EditFrame();editstu.init();/ 修改監(jiān)聽器class editAction implements ActionListener public void actionPerformed(ActionEvent e) Student stu = getStudent();boolean b = studao.edit(stu.getSno(), stu.getName(), stu.getSex(),stu.getAge(), stu.getClassName(), stu.getDepart(), conn);if (b) JOptionPane.showMessageDialog(null, "數(shù)據(jù)修改成功!"); else JOptionPane.showMessageDialog(null, "數(shù)據(jù)修改失??!");class BackAction implements ActionListenerpublic void actionPerformed(ActionEvent e) MainFrame m=new MainFrame (); m.init();專心-專注-專業(yè)