小试牛刀-教务信息管理系统(Operates)

来源:互联网 发布:好看网络剧推荐 编辑:程序博客网 时间:2024/05/10 22:27
package StuAdmin;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.SQLException;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;public class Operates {JDialog dialog;JButton button;String studentid, courseid;JTextField score;int Confirm = 0, deptint = 0;Operates(JFrame f, String cno, String cname, String sno, String sname) {studentid = sno;courseid = cno;dialog = new JDialog(f, "登记成绩", true);dialog.setLayout(null);JLabel label = new JLabel("学生学号");label.setBounds(100, 50, 100, 30);dialog.add(label);JTextField textfield = new JTextField(sno);textfield.setBounds(220, 50, 100, 30);textfield.setEditable(false);dialog.add(textfield);label = new JLabel("学生姓名");label.setBounds(100, 100, 100, 30);dialog.add(label);textfield = new JTextField(sname);textfield.setBounds(220, 100, 100, 30);textfield.setEditable(false);dialog.add(textfield);label = new JLabel("课程名");label.setBounds(100, 150, 100, 30);dialog.add(label);textfield = new JTextField(cname);textfield.setBounds(220, 150, 100, 30);textfield.setEditable(false);dialog.add(textfield);label = new JLabel("成绩");label.setBounds(100, 200, 100, 30);dialog.add(label);score = new JTextField();score.setBounds(220, 200, 100, 30);dialog.add(score);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL setscore = new SQL();String text = "UPDATE stc SET score='" + score.getText()+ "' WHERE studentid='" + studentid+ "' AND courseid='" + courseid + "';";if (setscore.othersql(text) > 0) {JOptionPane.showMessageDialog(null, "成绩登记成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "成绩登记失败!");Confirm = 0;}}});button.setBounds(100, 250, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 250, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);}Operates(JFrame f, int Opkind, String no) throws SQLException {final JTextField sid, sname, sbirth, sphone, sadd, tid, tname, tphone, cid, cname, ccredit;final JComboBox dept;final String id = no;SQL sql = new SQL();String text = null;switch (Opkind) {case 1:text = "SELECT * FROM student WHERE studentid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "修改学生信息", true);dialog.setLayout(null);JLabel label = new JLabel("学号");label.setBounds(100, 50, 100, 20);dialog.add(label);sid = new JTextField(no);sid.setEditable(false);sid.setBounds(220, 50, 100, 20);dialog.add(sid);label = new JLabel("学生姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);sname = new JTextField(sql.resultSet.getString(2));sname.setBounds(220, 80, 100, 20);dialog.add(sname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);JTextField ssex = new JTextField(sql.resultSet.getString(3));ssex.setEditable(false);ssex.setBounds(220, 110, 100, 20);dialog.add(ssex);label = new JLabel("出生日期");label.setBounds(100, 140, 100, 20);dialog.add(label);sbirth = new JTextField(sql.resultSet.getString(4));sbirth.setBounds(220, 140, 100, 20);dialog.add(sbirth);label = new JLabel("学院");label.setBounds(100, 170, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(7) - 1);// JTextField sdept = new JTextField();dept.setBounds(220, 170, 100, 20);dialog.add(dept);label = new JLabel("联系方式");label.setBounds(100, 200, 100, 20);dialog.add(label);sphone = new JTextField(sql.resultSet.getString(5));sphone.setBounds(220, 200, 100, 20);dialog.add(sphone);label = new JLabel("籍贯");label.setBounds(100, 230, 100, 20);dialog.add(label);sadd = new JTextField(sql.resultSet.getString(6));sadd.setBounds(220, 230, 100, 20);dialog.add(sadd);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "UPDATE student SET studentname = '"+ sname.getText() + "',studentbirth='"+ sbirth.getText() + "',studentdepart='" + deptint+ "',studentphone='" + sphone.getText()+ "',studentadd='" + sadd.getText()+ "' WHERE studentid='" + sid.getText() + "'";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "修改学生信息成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "修改学生信息失败!");Confirm = 0;}}});button.setBounds(100, 270, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 270, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 2:text = "SELECT * FROM student WHERE studentid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "删除学生信息", true);dialog.setLayout(null);label = new JLabel("学号");label.setBounds(100, 50, 100, 20);dialog.add(label);sid = new JTextField(no);sid.setEditable(false);sid.setBounds(220, 50, 100, 20);dialog.add(sid);label = new JLabel("学生姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);sname = new JTextField(sql.resultSet.getString(2));sname.setEditable(false);sname.setBounds(220, 80, 100, 20);dialog.add(sname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);ssex = new JTextField(sql.resultSet.getString(3));ssex.setEditable(false);ssex.setBounds(220, 110, 100, 20);dialog.add(ssex);label = new JLabel("出生日期");label.setBounds(100, 140, 100, 20);dialog.add(label);sbirth = new JTextField(sql.resultSet.getString(4));sbirth.setEditable(false);sbirth.setBounds(220, 140, 100, 20);dialog.add(sbirth);label = new JLabel("学院");label.setBounds(100, 170, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(7) - 1);dept.setEnabled(false);dept.setBounds(220, 170, 100, 20);dialog.add(dept);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL setscore = new SQL();String text = "DELETE FROM student WHERE studentid='" + id+ "';";if (setscore.othersql(text) > 0) {JOptionPane.showMessageDialog(null, "删除学生成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "删除学生失败!");Confirm = 0;}}});button.setBounds(100, 210, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 210, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 3:text = "SELECT * FROM teacher WHERE teacherid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "修改教师信息", true);dialog.setLayout(null);label = new JLabel("教工号");label.setBounds(100, 50, 100, 20);dialog.add(label);tid = new JTextField(no);tid.setEditable(false);tid.setBounds(220, 50, 100, 20);dialog.add(tid);label = new JLabel("教师姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);tname = new JTextField(sql.resultSet.getString(2));tname.setBounds(220, 80, 100, 20);dialog.add(tname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);ssex = new JTextField(sql.resultSet.getString(3));ssex.setEditable(false);ssex.setBounds(220, 110, 100, 20);dialog.add(ssex);label = new JLabel("学院");label.setBounds(100, 140, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(5) - 1);dept.setBounds(220, 140, 100, 20);dialog.add(dept);label = new JLabel("联系方式");label.setBounds(100, 170, 100, 20);dialog.add(label);tphone = new JTextField(sql.resultSet.getString(4));tphone.setBounds(220, 170, 100, 20);dialog.add(tphone);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "UPDATE teacher SET teachername = '"+ tname.getText() + "',teacherdepart='" + deptint+ "',teacherphone='" + tphone.getText()+ "' WHERE teacherid='" + tid.getText() + "'";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "修改教师信息成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "修改教师信息失败!");Confirm = 0;}}});button.setBounds(100, 200, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 200, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 4:text = "SELECT * FROM teacher WHERE teacherid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "删除教师信息", true);dialog.setLayout(null);label = new JLabel("教工号");label.setBounds(100, 50, 100, 20);dialog.add(label);tid = new JTextField(no);tid.setEditable(false);tid.setBounds(220, 50, 100, 20);dialog.add(tid);label = new JLabel("教师姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);tname = new JTextField(sql.resultSet.getString(2));tname.setEditable(false);tname.setBounds(220, 80, 100, 20);dialog.add(tname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);ssex = new JTextField(sql.resultSet.getString(3));ssex.setEditable(false);ssex.setBounds(220, 110, 100, 20);dialog.add(ssex);label = new JLabel("学院");label.setBounds(100, 140, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(5) - 1);dept.setEnabled(false);dept.setBounds(220, 140, 100, 20);dialog.add(dept);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL setscore = new SQL();String text = "DELETE FROM teacher WHERE teacherid='" + id+ "';";if (setscore.othersql(text) > 0) {JOptionPane.showMessageDialog(null, "删除教师成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "删除教师失败!");Confirm = 0;}}});button.setBounds(100, 180, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 180, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 5:text = "SELECT * FROM course WHERE courseid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "修改课程信息", true);dialog.setLayout(null);label = new JLabel("课程编号");label.setBounds(100, 50, 100, 20);dialog.add(label);cid = new JTextField(no);cid.setEditable(false);cid.setBounds(220, 50, 100, 20);dialog.add(cid);label = new JLabel("课程名");label.setBounds(100, 80, 100, 20);dialog.add(label);cname = new JTextField(sql.resultSet.getString(2));cname.setBounds(220, 80, 100, 20);dialog.add(cname);label = new JLabel("所属学院");label.setBounds(100, 110, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(4) - 1);dept.setBounds(220, 110, 100, 20);dialog.add(dept);label = new JLabel("学分");label.setBounds(100, 140, 100, 20);dialog.add(label);ccredit = new JTextField(sql.resultSet.getInt(3));ccredit.setBounds(220, 140, 100, 20);dialog.add(ccredit);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "UPDATE course SET coursename = '"+ cname.getText() + "',coursedepart='" + deptint+ "',coursecredit='" + ccredit.getText()+ "' WHERE courseid='" + cid.getText() + "'";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "修改课程信息成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "修改课程信息失败!");Confirm = 0;}}});button.setBounds(100, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 6:text = "SELECT * FROM course WHERE courseid = '" + id + "'";sql.select(text);dialog = new JDialog(f, "删除课程信息", true);dialog.setLayout(null);label = new JLabel("课程编号");label.setBounds(100, 50, 100, 20);dialog.add(label);cid = new JTextField(no);cid.setEditable(false);cid.setBounds(220, 50, 100, 20);dialog.add(cid);label = new JLabel("课程名");label.setBounds(100, 80, 100, 20);dialog.add(label);cname = new JTextField(sql.resultSet.getString(2));cname.setEditable(false);cname.setBounds(220, 80, 100, 20);dialog.add(cname);label = new JLabel("所属学院");label.setBounds(100, 110, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setSelectedIndex(sql.resultSet.getInt(4) - 1);dept.setEnabled(false);dept.setBounds(220, 110, 100, 20);dialog.add(dept);label = new JLabel("学分");label.setBounds(100, 140, 100, 20);dialog.add(label);ccredit = new JTextField(sql.resultSet.getInt(3));ccredit.setEditable(false);ccredit.setBounds(220, 140, 100, 20);dialog.add(ccredit);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL setscore = new SQL();String text = "DELETE FROM course WHERE courseid='" + id+ "';";if (setscore.othersql(text) > 0) {JOptionPane.showMessageDialog(null, "删除课程成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "删除课程失败!");Confirm = 0;}}});button.setBounds(100, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;}}Operates(JFrame f, int Opkind) {final JTextField sid, sname, sbirth, sphone, sadd, tid, tname, tphone, cid, cname, ccredit;final JComboBox dept, sex;switch (Opkind) {case 1:dialog = new JDialog(f, "添加学生信息", true);dialog.setLayout(null);JLabel label = new JLabel("学号");label.setBounds(100, 50, 100, 20);dialog.add(label);// JTextFieldsid = new JTextField();sid.setBounds(220, 50, 100, 20);dialog.add(sid);label = new JLabel("学生姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);sname = new JTextField();sname.setBounds(220, 80, 100, 20);dialog.add(sname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);sex = new JComboBox();sex.addItem("男");sex.addItem("女");// JTextField ssex = new JTextField();sex.setBounds(220, 110, 100, 20);dialog.add(sex);label = new JLabel("出生日期");label.setBounds(100, 140, 100, 20);dialog.add(label);sbirth = new JTextField();sbirth.setBounds(220, 140, 100, 20);dialog.add(sbirth);label = new JLabel("学院");label.setBounds(100, 170, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");// JTextField sdept = new JTextField();dept.setBounds(220, 170, 100, 20);dialog.add(dept);label = new JLabel("联系方式");label.setBounds(100, 200, 100, 20);dialog.add(label);sphone = new JTextField();sphone.setBounds(220, 200, 100, 20);dialog.add(sphone);label = new JLabel("籍贯");label.setBounds(100, 230, 100, 20);dialog.add(label);sadd = new JTextField();sadd.setBounds(220, 230, 100, 20);dialog.add(sadd);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "INSERT INTO student VALUES ('" + sid.getText()+ "', '" + sname.getText() + "', '"+ sex.getSelectedItem() + "', '" + sbirth.getText()+ "', '" + sphone.getText() + "', '"+ sadd.getText() + "','" + deptint + "','');";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "添加学生成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "添加学生失败!");Confirm = 0;}}});button.setBounds(100, 270, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 270, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 2:dialog = new JDialog(f, "添加教师信息", true);dialog.setLayout(null);label = new JLabel("教工号");label.setBounds(100, 50, 100, 20);dialog.add(label);tid = new JTextField();tid.setBounds(220, 50, 100, 20);dialog.add(tid);label = new JLabel("教师姓名");label.setBounds(100, 80, 100, 20);dialog.add(label);tname = new JTextField();tname.setBounds(220, 80, 100, 20);dialog.add(tname);label = new JLabel("性别");label.setBounds(100, 110, 100, 20);dialog.add(label);sex = new JComboBox();sex.addItem("男");sex.addItem("女");sex.setBounds(220, 110, 100, 20);dialog.add(sex);label = new JLabel("学院");label.setBounds(100, 140, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setBounds(220, 140, 100, 20);dialog.add(dept);label = new JLabel("联系方式");label.setBounds(100, 170, 100, 20);dialog.add(label);tphone = new JTextField();tphone.setBounds(220, 170, 100, 20);dialog.add(tphone);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "INSERT INTO teacher VALUES ('" + tid.getText()+ "', '" + tname.getText() + "','"+ sex.getSelectedItem() + "', '" + tphone.getText()+ "',  '" + deptint + "','')";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "添加教师成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "添加教师失败!");Confirm = 0;}}});button.setBounds(100, 200, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 200, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;case 3:dialog = new JDialog(f, "添加课程信息", true);dialog.setLayout(null);label = new JLabel("课程编号");label.setBounds(100, 50, 100, 20);dialog.add(label);cid = new JTextField();cid.setBounds(220, 50, 100, 20);dialog.add(cid);label = new JLabel("课程名");label.setBounds(100, 80, 100, 20);dialog.add(label);cname = new JTextField();cname.setBounds(220, 80, 100, 20);dialog.add(cname);label = new JLabel("所属学院");label.setBounds(100, 110, 100, 20);dialog.add(label);dept = new JComboBox();// 给组合框增加条目dept.addItem("计算机学院");dept.addItem("管理学院");dept.addItem("理学院");dept.addItem("外国语学院");dept.setBounds(220, 110, 100, 20);dialog.add(dept);label = new JLabel("学分");label.setBounds(100, 140, 100, 20);dialog.add(label);ccredit = new JTextField();ccredit.setBounds(220, 140, 100, 20);dialog.add(ccredit);button = new JButton("提交");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SQL sql = new SQL();String sqltext = "SELECT departmentid FROM department WHERE departmentname = '"+ dept.getSelectedItem() + "'";try {deptint = sql.getintcell(sqltext);} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}sqltext = "INSERT INTO course VALUES ('" + cid.getText()+ "', '" + cname.getText() + "', '"+ ccredit.getText() + "', '" + deptint + "');";if (sql.othersql(sqltext) > 0) {JOptionPane.showMessageDialog(null, "添加课程成功!");Confirm = 1;dialog.dispose();} else {JOptionPane.showMessageDialog(null, "添加课程失败!");Confirm = 0;}}});button.setBounds(100, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);button = new JButton("取消");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dialog.dispose();}});button.setBounds(220, 170, 100, 30);button.setBackground(Color.WHITE);dialog.add(button);dialog.setBounds(450, 200, 450, 430); // 大小设置dialog.setVisible(true);break;}}}

0 0