当前位置:文档之家› 学生考勤管理系统(JAVA语言)

学生考勤管理系统(JAVA语言)

JAVA程序设计学生考勤管理系统课程名称:JAVA程序设计设计题目:学生考勤管理系统(JAVA)指导老师:XXX班级:数计X级X班姓名:XXX学号:XXXXXXXXXX时间:2016年某月某日编程工具:MyEclipse(盗版的)编程电脑:DELL操作系统:Windows 7(自己换的)显卡:NVIDIA编程环境:JAVA语言设计功能:●查看学生信息●学生考勤●增加,删除,修改学生信息实验代码:package manger;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import javax.swing.JDesktopPane; import javax.swing.JButton;import java.awt.Rectangle;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import javax.swing.JTextField;import javax.swing.JLabel;public class AddForm {private JFrame jFrame = null;private JPanel jContentPane = null; private JDesktopPane jDesktopPane = null; private JButton jButtonOK = null;private JButton jButtonCancel = null; private JTextField jTextName = null; private JTextField jTextNum = null; private JTextField jTextGrade = null;private JLabel jLabelName = null;private JLabel jLabelNum = null;private JLabel jLabelGrade = null;JFrame getJFrame() {if (jFrame == null) {jFrame = new JFrame();jFrame.setTitle("添加学生信息");jFrame.setSize(new Dimension(242, 205));Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//窗口居中显示screenSize = Toolkit.getDefaultToolkit().getScreenSize();jFrame.setLocation((screenSize.width-jFrame.getWidth())/2,(screenSize.height-jFrame.getHeig ht())/2 ); jFrame.setContentPane(getJContentPane());}return jFrame;}private JPanel getJContentPane() {if (jContentPane == null) {jContentPane = new JPanel();jContentPane.setLayout(new BorderLayout());jContentPane.add(getJDesktopPane(), BorderLayout.CENTER);}return jContentPane;}private JDesktopPane getJDesktopPane() {if (jDesktopPane == null) {jLabelGrade = new JLabel();jLabelGrade.setBounds(new Rectangle(30, 100, 38, 18));jLabelGrade.setText("班级:");jLabelNum = new JLabel();jLabelNum.setBounds(new Rectangle(30, 60, 38, 18));jLabelNum.setText("学号:");jLabelName = new JLabel();jLabelName.setBounds(new Rectangle(30, 20, 38, 18));jLabelName.setText("姓名:");jDesktopPane = new JDesktopPane();jDesktopPane.add(getJButtonOK(), null);jDesktopPane.add(getJButtonCancel(), null);jDesktopPane.add(getJTextName(), null);jDesktopPane.add(getJTextNum(), null);jDesktopPane.add(getJTextGrade(), null);jDesktopPane.add(jLabelName, null);jDesktopPane.add(jLabelNum, null);jDesktopPane.add(jLabelGrade, null);}return jDesktopPane;}private JButton getJButtonOK() {if (jButtonOK == null) {jButtonOK = new JButton();jButtonOK.setBounds(new Rectangle(20, 135, 80, 22));jButtonOK.setText("提交");jButtonOK.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) {try {AddSQL();} catch (Exception e1) {// TODO 自动生成catch 块e1.printStackTrace();} // TODO Auto-generated Event stub mouseClicked()}private void AddSQL() throws Exception {String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";String Str="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=StuInfo"; Connection con=null;Statement stmt=null;ResultSet rs=null;Class.forName(DBDriver);con=DriverManager.getConnection(Str);stmt=con.createStatement();String name = jTextName.getText();if(name.equals("")){stmt.close();con.close();JOptionPane.showMessageDialog(new JDialog(),"姓名不能为空!"); return;}String num = jTextNum.getText();if(num.equals("")){stmt.close();con.close();JOptionPane.showMessageDialog(new JDialog(),"学号不能为空!"); return;}else{rs = stmt.executeQuery("Select * From StuInfo where Num ='"+num+"'");if(rs.next()){stmt.close();con.close();JOptionPane.showMessageDialog(new JDialog(),"学号重复!");return;}}String grade = jTextGrade.getText();if(grade.equals("")){stmt.close();con.close();JOptionPane.showMessageDialog(new JDialog(),"班级不能为空!");return;}stmt.executeUpdate("Insert Into StuInfo Values('"+name+"','"+num+"','"+grade+"')"); stmt.close();con.close();MainForm.Reflesh();getJFrame().dispose();JOptionPane.showMessageDialog(new JDialog(),"添加成功!");}});}return jButtonOK;}private JButton getJButtonCancel() {if (jButtonCancel == null) {jButtonCancel = new JButton();jButtonCancel.setBounds(new Rectangle(137, 135, 80, 22)); jButtonCancel.setText("取消");jButtonCancel.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) {getJFrame().dispose();}});}return jButtonCancel;}private JTextField getJTextName() {if (jTextName == null) {jTextName = new JTextField();jTextName.setBounds(new Rectangle(90, 20, 120, 22)); }return jTextName;}private JTextField getJTextNum() {if (jTextNum == null) {jTextNum = new JTextField();jTextNum.setBounds(new Rectangle(90, 60, 120, 22)); }return jTextNum;}private JTextField getJTextGrade() {if (jTextGrade == null) {jTextGrade = new JTextField();jTextGrade.setBounds(new Rectangle(90, 100, 120, 22)); }return jTextGrade;}}程序效果:未知错误:应用程序无法正常启动,请单击“确定”以关闭该程序;。

相关主题