📄 classadd.java
字号:
package java_教务管理系统;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Rectangle;
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 classadd extends JPanel {
public classadd() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(3, 5, 860, 624));
jPanel1.setLayout(null);
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel1.setText("班级编号:");
jLabel1.setBounds(new Rectangle(52, 54, 129, 38));
txtclassno.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtclassno.setBounds(new Rectangle(175, 56, 165, 31));
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel2.setText("班主任姓名:");
jLabel2.setBounds(new Rectangle(442, 52, 122, 37));
txtclassmastername.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
txtclassmastername.setBounds(new Rectangle(586, 56, 182, 31));
txtclassmastername.addActionListener(new
classadd_jTextField2_actionAdapter(this));
jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel3.setText("学期:");
jLabel3.setBounds(new Rectangle(90, 94, 69, 43));
jLabel4.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel4.setText("班级类别:");
jLabel4.setBounds(new Rectangle(468, 99, 107, 38));
jLabel5.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel5.setText("开学时间:");
jLabel5.setBounds(new Rectangle(168, 135, 100, 44));
jLabel6.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel6.setText("年");
jLabel6.setBounds(new Rectangle(393, 140, 31, 30));
jLabel7.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel7.setText("月");
jLabel7.setBounds(new Rectangle(507, 141, 34, 27));
jLabel8.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel8.setText("日");
jLabel8.setBounds(new Rectangle(623, 140, 35, 30));
jLabel9.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel9.setText("毕业时间:");
jLabel9.setBounds(new Rectangle(169, 177, 103, 40));
jLabel10.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel10.setText("年");
jLabel10.setBounds(new Rectangle(397, 180, 28, 27));
jLabel11.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel11.setText("月");
jLabel11.setBounds(new Rectangle(505, 175, 37, 34));
jLabel12.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel12.setText("日");
jLabel12.setBounds(new Rectangle(624, 183, 20, 28));
jLabel13.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
jLabel13.setText("备注:");
jLabel13.setBounds(new Rectangle(205, 217, 68, 42));
txaclassRemarks.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
txaclassRemarks.setBounds(new Rectangle(295, 225, 473, 78));
cboendtimedate.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cboendtimedate.setBounds(new Rectangle(543, 183, 70, 28));
cboendtimemonth.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cboendtimemonth.setBounds(new Rectangle(427, 182, 67, 29));
cboendtimeyear.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cboendtimeyear.setBounds(new Rectangle(295, 182, 91, 29));
cbobeginstimedate.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbobeginstimedate.setBounds(new Rectangle(543, 140, 70, 28));
cbobeginstimemonth.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbobeginstimemonth.setBounds(new Rectangle(427, 140, 67, 28));
cbobeginstimeyear.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cbobeginstimeyear.setBounds(new Rectangle(295, 141, 91, 29));
cboclasscategory.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cboclasscategory.setBounds(new Rectangle(587, 104, 103, 28));
cboclassSemester.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
cboclassSemester.setBounds(new Rectangle(174, 104, 91, 28));
jLabel14.setText("jLabel14");
jLabel14.setBounds(new Rectangle(28, 36, 36, 15));
btnclassadd.setBounds(new Rectangle(369, 318, 113, 33));
btnclassadd.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnclassadd.setText("添加班级");
btnclassadd.addActionListener(new classadd_btnclassadd_actionAdapter(this));
btnexit.setBounds(new Rectangle(487, 318, 113, 33));
btnexit.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnexit.setText("退出添加");
btnok.setBounds(new Rectangle(251, 318, 113, 33));
btnok.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
btnok.setText("检测编号");
btnok.addActionListener(new classadd_btnok_actionAdapter(this));
jPanel1.add(cbobeginstimemonth);
jPanel1.add(cboendtimemonth);
jPanel1.add(jLabel1);
jPanel1.add(txtclassno);
jPanel1.add(jLabel2);
jPanel1.add(txtclassmastername);
jPanel1.add(cboclasscategory);
jPanel1.add(jLabel4);
jPanel1.add(cbobeginstimedate);
jPanel1.add(jLabel8);
jPanel1.add(jLabel12);
jPanel1.add(cboendtimedate);
jPanel1.add(jLabel11);
jPanel1.add(jLabel7);
jPanel1.add(jLabel10);
jPanel1.add(jLabel6);
jPanel1.add(cbobeginstimeyear);
jPanel1.add(cboendtimeyear);
jPanel1.add(jLabel9);
jPanel1.add(jLabel5);
jPanel1.add(cboclassSemester);
jPanel1.add(jLabel3);
jPanel1.add(txaclassRemarks);
jPanel1.add(jLabel13);
jPanel1.add(btnok);
jPanel1.add(btnclassadd);
jPanel1.add(btnexit);
this.add(jPanel1);
}
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JTextField txtclassno = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField txtclassmastername = new JTextField();
JLabel jLabel3 = new JLabel();
//班级年级
String Semester[] = {"S1", "S2", "Y2"};
JComboBox cboclassSemester = new JComboBox(Semester);
JLabel jLabel4 = new JLabel();
//班级类别
String category[] = {"脱产班", "周末班"};
JComboBox cboclasscategory = new JComboBox(category);
JLabel jLabel5 = new JLabel();
//开学时间(年)
String beginstimeyear[] = {"2006", "2007", "2008", "2009"};
JComboBox cbobeginstimeyear = new JComboBox(beginstimeyear);
JLabel jLabel6 = new JLabel();
//开学时间(月)
String beginstimemonth[] = {"01", "02", "03", "04", "05", "06", "07", "08",
"09",
"10", "11", "12"};
JComboBox cbobeginstimemonth = new JComboBox(beginstimemonth);
JLabel jLabel7 = new JLabel();
//开学时间(日)
String beginstimedate[] = {"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"};
JComboBox cbobeginstimedate = new JComboBox(beginstimedate);
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
//毕业时间(年)
String endtimeyear[] = {"2006", "2007", "2008", "2009"};
JComboBox cboendtimeyear = new JComboBox(endtimeyear);
JLabel jLabel10 = new JLabel();
//毕业时间(月)
String endtimemonth[] = {"01", "02", "03", "04", "05", "06", "07", "08",
"09",
"10", "11", "12"};
JComboBox cboendtimemonth = new JComboBox(endtimemonth);
JLabel jLabel11 = new JLabel();
//毕业时间(日)
String endtimedate[] = {"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"};
JComboBox cboendtimedate = new JComboBox(endtimedate);
JLabel jLabel12 = new JLabel();
JLabel jLabel13 = new JLabel();
JTextArea txaclassRemarks = new JTextArea();
JLabel jLabel14 = new JLabel();
JButton btnclassadd = new JButton();
JButton btnexit = new JButton();
JButton btnok = new JButton();
public void jTextField2_actionPerformed(ActionEvent e) {
}
public void btnclassadd_actionPerformed(ActionEvent e) {
try {
//班级类别classcategory
String categoryname = this.cboclasscategory.getSelectedItem().
toString();
//学期classSemester
String Semestername = this.cboclassSemester.getSelectedItem().
toString();
//开学时间
String beginstimename =
this.cbobeginstimeyear.getSelectedItem().toString() + "-" +
this.cbobeginstimemonth.getSelectedItem().toString() + "-" +
this.cbobeginstimedate.getSelectedItem().toString() + " ";
//毕业时间
String endtimename =
this.cboendtimeyear.getSelectedItem().toString() + "-" +
this.cboendtimemonth.getSelectedItem().toString() + "-" +
this.cboendtimedate.getSelectedItem().toString() + " ";
if (this.txtclassno.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 class (classno,classmastername,classSemester,classcategory,beginstime,endtime,classRemarks) values(?,?,?,?,?,?,?)");
sql.setString(1, this.txtclassno.getText());
sql.setString(2, this.txtclassmastername.getText());
sql.setString(3, Semestername);
sql.setString(4, categoryname);
sql.setString(5, beginstimename);
sql.setString(6, endtimename);
sql.setString(7, this.txaclassRemarks.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 classno from class where classno = '" +
this.txtclassno.getText() + "'";
PreparedStatement sql = nod.prepareStatement(
daima);
ResultSet i = sql.executeQuery();
String no = this.txtclassno.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 classadd_btnok_actionAdapter implements ActionListener {
private classadd adaptee;
classadd_btnok_actionAdapter(classadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnok_actionPerformed(e);
}
}
class classadd_btnclassadd_actionAdapter implements ActionListener {
private classadd adaptee;
classadd_btnclassadd_actionAdapter(classadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnclassadd_actionPerformed(e);
}
}
class classadd_jTextField2_actionAdapter implements ActionListener {
private classadd adaptee;
classadd_jTextField2_actionAdapter(classadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextField2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -