package test;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
public class TeacherFrame implements ActionListener{
Graphics g;
MyDBConnection mydbcon;
Connection conn;
Statement stam;
String accountNum;
String accountName;
String Tno;
String Tname;
String Tsex;
int Tage;
String work;
String code;
String Tpower;
JFrame stf = new JFrame("选课管理系统——教师");
JSplitPane stf_sp1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
JSplitPane stf_sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
JSplitPane stf_sp3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
JSplitPane stf_sp4 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
JPanel stf_p1 = new JPanel();
JPanel stf_p2 = new JPanel();
JPanel stf_p3 = new JPanel();
JPanel stf_p4 = new JPanel();
JPanel stf_p5 = new JPanel();
JPanel stf_p6 = new JPanel();
JPanel stf_p7 = new JPanel();//按钮主界面
JPanel stf_p8 = new JPanel();
JPanel stf_p9 = new JPanel();
JPanel stf_p10 = new JPanel();
JPanel stf_p11 = new JPanel();//修改信息界面
JPanel stf_p12 = new JPanel();
JPanel stf_p13 = new JPanel();
JPanel stf_p14 = new JPanel();
JPanel stf_p15 = new JPanel();
JPanel stf_p16 = new JPanel();
JPanel stf_p17 = new JPanel();
JPanel stf_p18 = new JPanel();
JPanel stf_p19 = new JPanel();//
JPanel stf_p20 = new JPanel();//第一界面
JPanel stf_p21 = new JPanel();
JPanel stf_p22 = new JPanel();
JPanel stf_p23 = new JPanel();
JPanel stf_p24 = new JPanel();
JPanel stf_p25 = new JPanel();
JPanel stf_p26 = new JPanel();
JPanel stf_p27 = new JPanel();//
JPanel stf_p28 = new JPanel();//写成绩面板
JPanel stf_p29 = new JPanel();
JPanel stf_p30 = new JPanel();
JPanel stf_p31 = new JPanel();//
JPanel stf_p32 = new JPanel();//开课界面
JPanel stf_p33 = new JPanel();
JPanel stf_p34 = new JPanel();
JPanel stf_p35 = new JPanel();
JPanel stf_p36 = new JPanel();//
JLabel stf_l1 = new JLabel();
JLabel stf_l2 = new JLabel();
JLabel stf_l3 = new JLabel("欢迎您!");
JLabel stf_l4 = new JLabel("课程号:");
JLabel stf_l5 = new JLabel("课程名:");
JLabel stf_l6 = new JLabel("开课时间");
JLabel stf_l7 = new JLabel("学分");
JLabel stf_l8 = new JLabel("地点");
JLabel stf_l9 = new JLabel("年份");
JLabel stf_l10 = new JLabel("学期");
JLabel stf_l16 = new JLabel("选择学号:");
JLabel stf_l17 = new JLabel("课程名:+");
JLabel stf_l18 = new JLabel("成绩:");
JLabel stf_l19 = new JLabel("课程号");
JButton stf_b1 = new JButton("修改信息");
JButton stf_b2 = new JButton("开课");
JButton stf_b3 = new JButton("写成绩");
JButton stf_b4 = new JButton("查询开课");
JButton stf_b5 = new JButton("创建课程");
JButton stf_b6 = new JButton("修改密码");
JButton stf_b7 = new JButton("录入成绩");
JButton stf_b8 = new JButton("我的课程");
JButton stf_b9 = new JButton("全部课程");
JButton stf_b10 = new JButton("加入课程");
JButton stf_b11 = new JButton("清除课程人员");
JButton stf_b12 = new JButton("查询");
JButton stf_b13 = new JButton("查询课程");
JButton stf_b14 = new JButton("退出课程");
JTextField stf_t1 = new JTextField(20);
JTextField stf_t2 = new JTextField(20);
JTextField stf_t3 = new JTextField(20);
JTextField stf_t4 = new JTextField(20);
JTextField stf_t5 = new JTextField(20);
JTextField stf_t6 = new JTextField(20);
JTextField stf_t7 = new JTextField(20);
JTextField stf_t8 = new JTextField(20);
JTextField stf_t9 = new JTextField(20);
JTextField stf_t10 = new JTextField(20);
JTextField stf_t11 = new JTextField(20);
JTextField stf_t12 = new JTextField(20);
JTextField stf_t13 = new JTextField(15);
JTextField stf_t14 = new JTextField(20);
JTextField stf_t15 = new JTextField(15);
/*JTextField stf_t16 = new JTextField(20);//
JTextField stf_t17 = new JTextField(20);
JTextField stf_t18 = new JTextField(20);//
JTextField stf_t19 = new JTextField(20);*/
ImageIcon img1 = new ImageIcon("src/test/4.jpg");
ImageIcon img2 = new ImageIcon("src/test/5.jpg");
String[] columnNames1 = {"课程号","课程名","上课时间","地点","学分","开设学年","开设学期","已选人数"};
String[] columnNames2 = {"学号","姓名","成绩"};
String [][] data1 = { };
//创建表格并设置表格只读
DefaultTableModel model1 = new DefaultTableModel(data1, columnNames1) {
private static final long serialVersionUID = 1L;
public boolean isCellEditable(int row, int column) {
return false;
}
};
String [][] data2 = { };
//创建表格并设置表格只读
DefaultTableModel model2 = new DefaultTableModel(data2, columnNames2) {
private static final long serialVersionUID = 1L;
public boolean isCellEditable(int row, int column) {
return false;
}
};
JTable table1= new JTable(model1);
JTable table2= new JTable(model2);
JScrollPane scroll1 = new JScrollPane(table1);
JScrollPane scroll2 = new JScrollPane(table2);
public TeacherFrame(MyDBConnection mydbcon,String accountNum) {
this.mydbcon = mydbcon;
this.conn = mydbcon.getMyConnection();
this.stam = mydbcon.getMyStatement();
this.accountNum = accountNum;
drawUI();
stf_b1.addActionListener(this);
stf_b2.addActionListener(this);
stf_b3.addActionListener(this);
stf_b4.addActionListener(this);
stf_b5.addActionListener(this);
stf_b6.addActionListener(this);
stf_b7.addActionListener(this);
stf_b8.addActionListener(this);
stf_b9.addActionListener(this);
stf_b10.addActionListener(this);
stf_b11.addActionListener(this);
stf_b12.addActionListener(this);
stf_b13.addActionListener(this);
stf_b14.addActionListener(this);
}
private void drawUI() {
stf.setVisible(true);
stf.setSize(1000, 800);
stf.setLocationRelativeTo(null);
stf.setDefaultCloseOperation(stf.DISPOSE_ON_CLOSE);
img1.setImage(img1.getImage().getScaledInstance(1000, 100,Image.SCALE_DEFAULT));
stf_l1.setIcon(img1);
stf_sp1.setLeftComponent(stf_l1);
stf_sp1.setDividerLocation(100);
stf_sp1.setDividerSize(8);
stf_sp2.setLeftComponent(stf_sp4);
stf_sp2.setRightComponent(stf_p2);//右部显示界面
stf_sp2.setDividerLocation(250);
stf_sp2.setDividerSize(8);
stf_sp2.setOneTouchExpandable(true);
stf_sp2.setContinuousLayout(true);
stf_sp1.setRightComponent(stf_sp2);
stf.add(stf_sp1);
stf_sp3.setLeftComponent(stf_p3);
stf_sp3.setRightComponent(stf_p4);
stf_sp3.setDividerLocation(250);
stf_sp3.setDividerSize(8);
stf_sp3.setOneTouchExpandable(true);
stf_sp3.setContinuousLayout(true);
stf_sp4.add(stf_sp3);
stf_p3.setLayout(new GridLayout(2,1));
stf_p3.add(stf_p5);stf_p3.add(stf_p6);
img2.setImage(img2.getImage().getScaledInstance(100, 100,Image.SCALE_DEFAULT));
stf_l2.setIcon(img2);
stf_p5.add(stf_l2);
stf_l3.setFont(new Font("Dialog", 1, 25));
selecetAccountName();
Teacherinformation();
JLabel stf_l4 = new JLabel(accountName+"教师");
stf_l4.setFont(new Font("Dialog", 1, 25));
stf_p6.add(stf_l3);stf_p6.add(stf_l4);
stf_p4.setLayout(new GridLayout(4,1));
stf_p4.add(stf_p7); stf_p4.add(stf_p8); stf_p4.add(stf_p9); stf_p4.add(stf_p10);
stf_p7.add(stf_b1); stf_p8.add(stf_b2); stf_p9.add(stf_b3); stf_p10.add(stf_b4);
}
private void selecetAccountName() {
String sql = "select * from tb_Teacher where Tno = "+accountNum.trim()+"";
try {
ResultSet re = stam.executeQuery(sql);
re.next();
accountName = re.getString("Tname");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void Teacherinformation() {
String sql = "select * from tb_Teacher where Tno = "+accountNum.trim()+"";
try {
ResultSet