📄 jpanel1.java~50~
字号:
package guanlixitong;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.table.*;
public class JPanel1
extends JPanel implements ActionListener {
public JPanel1() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
jLabel3.setText("");
if (e.getSource() == jButton1) {
int m = Integer.parseInt(jTextField1.getText());
if (m <= 109 && m >= 101&&n<5&&tof(m)) {
String str = "jdbc:odbc:yangAcess";
Connection con;
String select = "select 上课时间,上课地点,学分,课序号 from yang2 where 课序号=" + m;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(str);
Statement stmt = con.createStatement();
rs = stmt.executeQuery(select);
n = n + 1;
while (rs.next()) {
课程[n-1].上课时间 = rs.getString(1);
课程[n-1].上课地点 = rs.getString(2);
课程[n-1].学分 = rs.getString(3);
课程[n-1].课序号 = rs.getInt(4);
}
}
catch (Exception ea) {}
initTabel();
String update="update yang1 set 课程1="+课程[0].课序号+",课程2="+课程[1].课序号+
", 课程3="+课程[2].课序号+",课程4="+课程[3].课序号+
", 课程5="+课程[4].课序号+ " where 学号="+num;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(str);
Statement up=con.createStatement();
up.executeUpdate(update);
up.close();
con.close();
}catch(Exception ae ){System.out.print("fool");}
}
}
else if (e.getSource() == jButton2) {
for (int i = 0; i < 5; i++) {
课程[i] = new 课程();
}
num = Integer.parseInt(jTextField2.getText());
int num1 = -1;
String str = "jdbc:odbc:yangAcess";
Connection con;
n = 0;
String select = "select 学号 from yang1 where 学号=" + num;
String sSelect =
"select 上课时间,上课地点,学分,课序号 from yang2 where 课序号=(select 课程1 from yang1 where 学号=" +
num +
")or 课序号=( select 课程2 from yang1 where 学号=" + num +
")or 课序号=(select 课程3 from yang1 where 学号=" + num +
")or 课序号=(select 课程4 from yang1 where 学号=" + num +
")or 课序号=(select 课程5 from yang1 where 学号=" + num + ")";
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(str);
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sSelect);
while (rs.next()) {
课程[n].上课时间 = rs.getString(1);
课程[n].上课地点 = rs.getString(2);
课程[n].学分 = rs.getString(3);
课程[n].课序号 = rs.getInt(4);
n++;
}
rs = stmt.executeQuery(select);
while (rs.next()) {
num1 = rs.getInt(1);
}
con.close();
stmt.close();
}
catch (Exception ae) {
System.out.print("Woring");
}
if(num==num1){
initTabel();
jTextField1.setEnabled(true);
jButton1.setEnabled(true);
jLabel1.setEnabled(true);
}
else{
jLabel3.setText(" 你 所 输 学 号 不 存 在");
}
}
}
public boolean tof(int a){
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1;j++){
if(课程[j].课序号>课程[j+1].课序号){
int n=课程[j].课序号;
课程[j].课序号=课程[j+1].课序号;
课程[j+1].课序号=n;
}
}
}
return (a!=课程[0].课序号&&a!=课程[1].课序号&&a!=课程[2].课序号&&a!=课程[3].课序号&&a!=课程[4].课序号);
}
public void initTabel() {
jtm = new DefaultTableModel();
jtm.setRowCount(n);
jtm.addColumn("课序号");
jtm.addColumn("上课时间");
jtm.addColumn("上课地点");
jtm.addColumn("学分");
jb.setEnabled(false);
for (int i = 0; i < n; i++) {
jtm.setValueAt(new Integer(课程[i].课序号), i, 0);
jtm.setValueAt(课程[i].上课时间, i, 1);
jtm.setValueAt(课程[i].上课地点, i, 2);
jtm.setValueAt(课程[i].学分, i, 3);
}
jb.setModel(jtm);
}
private void jbInit() throws Exception {
this.setLayout(null);
jScrollPane1.setEnabled(false);
jScrollPane1.setBounds(new Rectangle(195, 181, 412, 117));
jTextField1.setEnabled(false);
jTextField1.setBounds(new Rectangle(310, 440, 123, 32));
jLabel1.setEnabled(false);
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLabel1.setForeground(Color.magenta);
jLabel1.setText("课 序 号");
jLabel1.setBounds(new Rectangle(195, 440, 107, 33));
jButton1.setBounds(new Rectangle(475, 441, 133, 32));
jButton1.setEnabled(false);
jButton1.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jButton1.setForeground(Color.magenta);
jButton1.setText("提 交");
jTextField2.setBounds(new Rectangle(283, 92, 181, 29));
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLabel2.setForeground(Color.magenta);
jLabel2.setText("学 号");
jLabel2.setBounds(new Rectangle(195, 92, 70, 29));
jButton2.setBounds(new Rectangle(526, 92, 81, 29));
jButton2.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jButton2.setForeground(Color.magenta);
jButton2.setText("确 定");
jLabel3.setFont(new java.awt.Font("新宋体", Font.BOLD, 16));
jLabel3.setForeground(Color.red);
jLabel3.setBounds(new Rectangle(268, 31, 276, 28));
jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel4.setForeground(Color.red);
jLabel4.setText("你 最 多 选 五 门 课 程");
jLabel4.setBounds(new Rectangle(276, 393, 218, 31));
jCheckBox1.setEnabled(false);
jCheckBox1.setSelectedIcon(null);
jCheckBox1.setText("jCheckBox1");
jCheckBox1.setBounds(new Rectangle(166, 204, 19, 13));
jCheckBox2.setEnabled(false);
jCheckBox2.setText("jCheckBox2");
jCheckBox2.setBounds(new Rectangle(166, 230, 18, 18));
jCheckBox3.setEnabled(false);
jCheckBox3.setText("jCheckBox2");
jCheckBox3.setBounds(new Rectangle(166, 245, 18, 18));
jCheckBox4.setEnabled(false);
jCheckBox4.setText("jCheckBox2");
jCheckBox4.setBounds(new Rectangle(166, 263, 18, 16));
jCheckBox5.setEnabled(false);
jCheckBox5.setText("jCheckBox2");
jCheckBox5.setBounds(new Rectangle(166, 217, 18, 18));
jButton3.setBounds(new Rectangle(195, 342, 135, 31));
jButton3.setEnabled(false);
jButton3.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jButton3.setForeground(Color.magenta);
jButton3.setText("删 除 ");
this.add(jLabel1);
this.add(jButton1);
this.add(jTextField1);
this.add(jScrollPane1);
this.add(jButton2);
this.add(jTextField2);
this.add(jLabel2);
this.add(jLabel3);
this.add(jLabel4);
this.add(jCheckBox2);
this.add(jCheckBox4);
this.add(jCheckBox1);
this.add(jCheckBox5);
this.add(jCheckBox3);
this.add(jButton3);
jScrollPane1.getViewport().add(jb, null);
jButton1.addActionListener(this);
jButton2.addActionListener(this);
for (int i = 0; i < 5; i++) {
课程[i] = new 课程();
}
}
JScrollPane jScrollPane1 = new JScrollPane();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JTextField jTextField2 = new JTextField();
JLabel jLabel2 = new JLabel();
JButton jButton2 = new JButton();
JTable jb = new JTable();
DefaultTableModel jtm;
课程[] 课程 = new 课程[5];
int n = 0;
int num;
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
int a=0;
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JCheckBox jCheckBox4 = new JCheckBox();
JCheckBox jCheckBox5 = new JCheckBox();
JButton jButton3 = new JButton();
private class 课程 {
int 课序号;
String 学分, 上课地点, 上课时间;
public 课程() {
课序号 =a++;
学分 = "0";
上课地点 = "";
上课时间 = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -