📄 teacher.java
字号:
package test;
import java.awt.*;
import java.io.*;//输入输出
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class Teacher extends JFrame implements ActionListener{
int n,aa;
sql sqll;ResultSet rs;String jiaoshihao="101";sql sqll2;ResultSet rs2;sql sqll3;ResultSet rs3;sql2 sql21,sql22;
JButton b1=new JButton("本人信息");
JButton b3=new JButton("授课一览");
JButton b4=new JButton("选课人数");
JButton b5=new JButton("选课学生一览");
JButton b6=new JButton("成绩录入");
JButton b7=new JButton("查询");
JButton b8=new JButton("成绩修改");
JButton b9=new JButton("查看学生信息");
JButton b10=new JButton("成绩一览");
JLabel jj1=new JLabel("输入学生学号");
JLabel jj2=new JLabel("输入课程号号");
JLabel jj11=new JLabel("输入学生学号");
JLabel jj22=new JLabel("输入课程号号");
JLabel jj33=new JLabel("输入成绩");
JButton bbb5=new JButton("修改");
JTextField field1,field2,field3,field4;
JScrollPane js1,js2;
JComboBox jcb1,jcb2;
JLabel j1=new JLabel("学号");JLabel j2=new JLabel("姓名");JLabel j3=new JLabel("性别");
JLabel j4=new JLabel("年龄");JLabel j5=new JLabel("院系号");
JLabel jj4=new JLabel("课程号");JLabel jj5=new JLabel("课程名");
JLabel jj6=new JLabel("先行课");JLabel jj7=new JLabel("学分");
JTextField ff1,ff2,ff3,ff4,ff5,ff6,ff7,ff8,ff9;
JTextField fff1,fff2,fff3,fff4;
JTabbedPane jtp; JTextArea ja,ja2,ja3,ja4;
public Teacher (){
ff1=new JTextField(10); ff2=new JTextField(10); ff3=new JTextField(10); ff4=new JTextField(10);
ff5=new JTextField(10); ff6=new JTextField(10); ff7=new JTextField(10); ff8=new JTextField(10);
Container contentpane=getContentPane();
setBounds(500,400,500,400);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("教师界面");
JPanel p1=new JPanel(),p2=new JPanel(),p3 =new JPanel(),p4 =new JPanel(),p5 =new JPanel();
JPanel p6=new JPanel(),p7=new JPanel(),p8 =new JPanel(),p9 =new JPanel(),p10 =new JPanel();
JPanel pa1=new JPanel(),pa2=new JPanel(),pa3 =new JPanel(),pa4 =new JPanel(),pa5 =new JPanel();
JPanel pa6=new JPanel(),pa7=new JPanel(),pa8 =new JPanel(),pa9 =new JPanel(),pa10 =new JPanel(),pa11 =new JPanel();
JPanel p16=new JPanel(),p15=new JPanel(),p17=new JPanel(),p18 =new JPanel(),p19 =new JPanel(),p20 =new JPanel(),p21 =new JPanel();
ja=new JTextArea(15,30);ja2=new JTextArea(10,15);ja3=new JTextArea(10,15);ja4=new JTextArea(10,15);
//................................................
jtp=new JTabbedPane();
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
jtp=new JTabbedPane();
//jp1.setBackground(Color.yellow);
jp2.setBackground(Color.black);
jp3.setBackground(Color.green);
jp4.setBackground(Color.blue);
jtp.add(jp1,"本人信息");
jtp.add(jp2,"查看选课");
jtp.add(jp3,"管理课程");
jtp.add(jp4,"录入成绩");
//************************************************
contentpane.add(jtp);
jp1.setLayout(new BorderLayout());
jp1.add(p1,BorderLayout.NORTH);
//p1.setLayout(new GridLayout(1,1));
p1.add(b1);b1.addActionListener(this);
jp1.add(p2,BorderLayout.CENTER);
p2.add(ja);p2.setBackground(Color.BLUE);
//***************************************************
b3.addActionListener(this); b4.addActionListener(this); b7.addActionListener(this); bbb5.addActionListener(this);
b5.addActionListener(this); b6.addActionListener(this);b8.addActionListener(this);b9.addActionListener(this);
b10.addActionListener(this);
//********************************************************
jp2.setLayout(new BorderLayout());
js1=new JScrollPane(ja2);
jp2.add(p3,BorderLayout.NORTH);
p3.setLayout(new FlowLayout());
p3.add(b3);p3.add(b4);//p3.add(b6);
jp2.add(p4,BorderLayout.CENTER);
p4.setLayout(new GridLayout(1,2));
p4.add(pa1);p4.add(pa2);
pa1.setLayout(new GridLayout(5,1));
pa1.add(pa3); pa1.add(pa4); pa1.add(pa5); pa1.add(pa6); pa1.add(pa7);
pa3.setLayout(new FlowLayout()); pa4.setLayout(new FlowLayout());
pa5.setLayout(new FlowLayout()); pa6.setLayout(new FlowLayout()); pa7.setLayout(new FlowLayout());
pa3.add(j1); pa3.add(ff1);
pa4.add(j2); pa4.add(ff2);
pa5.add(j3); pa5.add(ff3);
pa6.add(j4); pa6.add(ff4);
pa7.add(j5); pa7.add(ff5);
p4.setBackground(Color.green);
pa2.add(js1);
jp2.add(p5,BorderLayout.SOUTH);
p5.setLayout(new GridLayout(2,1));
p5.add(pa8);p5.add(pa9);
field1=new JTextField(10);field4=new JTextField(10);
pa8.add(jj1);pa8.add(field1);pa8.add(b9);
pa9.add(jj2);pa9.add(field4);pa9.add(b5);
//************************************************************************************************8
fff1=new JTextField(10); fff2=new JTextField(10); fff3=new JTextField(10); fff4=new JTextField(10);
jp3.setLayout(new BorderLayout());
jp3.add(p15,BorderLayout.NORTH);
jcb2=new JComboBox();
jcb2.addItem("按课程号查询"); jcb2.addItem("按课程名查询");
field3=new JTextField(10);
p15.add(jcb2);p15.add(field3);p15.add(b7);
jp3.add(p16,BorderLayout.CENTER);
p16.setLayout(new GridLayout(5,1));
p16.add(p17); p16.add(p18); p16.add(p19); p16.add(p20);
p17.setLayout(new FlowLayout()); p18.setLayout(new FlowLayout());
p19.setLayout(new FlowLayout()); p20.setLayout(new FlowLayout());
p17.add(jj4); p17.add(fff1);
p18.add(jj5); p18.add(fff2);
p19.add(jj6); p19.add(fff3);
p20.add(jj7); p20.add(fff4);
jp3.add(p21,BorderLayout.SOUTH);
p21.add(bbb5);
//************************************************************************************************8
js2=new JScrollPane(ja4);
jp4.setLayout(new BorderLayout());
jp4.add(p6,BorderLayout.NORTH);
p6.add(b6); p6.add(b8);p6.add(b10);
jp4.add(pa10,BorderLayout.CENTER);
pa10.setLayout(new GridLayout(1,2));
pa10.add(p7); pa10.add(pa11);
pa11.add(js2);
p7.setLayout(new GridLayout(3,1));
p7.add(p8);p8.setLayout(new FlowLayout());
p7.add(p9);p9.setLayout(new FlowLayout());
p7.add(p10);p10.setLayout(new FlowLayout());
p8.add(jj11); p8.add(ff6);
p9.add(jj22); p9.add(ff7);
p10.add(jj33); p10.add(ff8);
}
public static void main(String[] args){
Teacher good=new Teacher();
good.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b3){System.out.println(this.jiaoshihao);
String s="select *from shouke where 教师号="+this.jiaoshihao;
sqll=new sql();
try{rs=sqll.execsql(s); ja2.append("\n"+"教师号"+" "+"课程号");
while(rs.next()){
ja2.append("\n"+rs.getString(1)+rs.getString(2));
}
}catch(Exception f){f.printStackTrace(); }
}
// ************************************************************************************************8
if(e.getSource()==b5){
String s="select student.学号,student.姓名 from xuanke,student where xuanke.学号=student.学号 and xuanke.课程号="+field4.getText().trim();
sqll3=new sql();
try{rs3=sqll3.execsql(s); ja2.append("\n"+"学号"+" "+"姓名");
while(rs3.next()){// n++;
ja2.append("\n"+rs3.getString(1)+rs3.getString(2));
// ja2.append("\n"+"该门课选课人数为"+" "+n);
//ja.append("\n");
} rs3.close();
}catch(Exception f){f.printStackTrace(); }
}
// ************************************************************************************************8
if(e.getSource()==b4){
String s="select count(学号) from xuanke where xuanke.课程号="+field4.getText().trim();
sqll3=new sql();
try{rs3=sqll3.execsql(s);
ja2.append("\n"+"该门课选课人数为"+rs3.getString(1));
}catch(Exception f){f.printStackTrace(); }
}
if(e.getSource()==b9 ){
String s="select *from student where 学号="+field1.getText().trim();
sqll=new sql();
try{rs=sqll.execsql(s);
while(rs.next()){
//ja.append("\n"+rs.getString(1)+rs.getString(2)+rs.getString(3)+rs.getString(4)+" "+rs.getString(5));
ff1.setText(rs.getString(1).trim()); ff2.setText(rs.getString(2).trim());
ff3.setText(rs.getString(3).trim()); ff4.setText(rs.getString(4).trim());
ff5.setText(rs.getString(5).trim());
}
}catch(Exception f){f.printStackTrace(); }
}
//********************************************************************************************************************
if(e.getSource()==b6 ){
if(ff6.getText().trim().isEmpty()||ff7.getText().trim().isEmpty()||ff8.getText().trim().isEmpty())
{JOptionPane.showMessageDialog(this,"不得为空!"+JOptionPane.WARNING_MESSAGE);}
else {
String s="select *from xuanke where 学号="+ff6.getText().trim()+"and 课程号="+ff7.getText().trim();
String s2="insert into xuanke(学号,课程号,成绩) values('"+ff6.getText().trim()+"','"+ff7.getText().trim()+"','"+ff8.getText().trim()+"')";
// String s3="insert into student(ff1.getText().trim(),ff2.getText().trim(),ff3.getText().trim(),ff4.getText().trim(),ff5.getText().trim())";
sqll=new sql();sql21=new sql2();
try{rs=sqll.execsql(s);
if(rs.next()){
JOptionPane.showMessageDialog(this,"已存在学号为"+ff6.getText().trim()+"课程号为"+ff7.getText().trim()+"的学生该门课成绩 添加操作被禁止!"+JOptionPane.WARNING_MESSAGE);
}
else{aa=sql21.execsql(s2);
if(aa>0)
JOptionPane.showMessageDialog(this,"添加成功!"+JOptionPane.WARNING_MESSAGE);
}
}catch(Exception f){f.printStackTrace(); }
}
}
// ********************************************************************************************************************
if(e.getSource()==b7&&jcb2.getSelectedItem().equals("按课程号查询") ){
String s="select *from course where 课程号="+field3.getText().trim();
sqll=new sql();
try{rs=sqll.execsql(s);
while(rs.next()){
//ja.append("\n"+rs.getString(1)+rs.getString(2)+rs.getString(3)+rs.getString(4)+" "+rs.getString(5));
fff1.setText(rs.getString(1).trim()); fff2.setText(rs.getString(2).trim());
fff3.setText(rs.getString(3).trim()); fff4.setText(rs.getString(4).trim());
}
}catch(Exception f){f.printStackTrace(); }
}
//********************************************************************************************************************
if(e.getSource()==bbb5 ){
if(fff1.getText().trim().isEmpty()){JOptionPane.showMessageDialog(this,"课程号不得为空!"+JOptionPane.WARNING_MESSAGE);}
else {
// String s="update student set 姓名="+ff2.getText().trim()+","+"性别="+ff3.getText().trim()+","+"年龄="+ff4.getText().trim()+",院系号="+ff3.getText().trim()+"where 学号="+ff1.getText().trim();
String s="update course set 课程号='"+fff1.getText().trim()+"',课程名='"+fff2.getText().trim()+"',先行课='"+fff3.getText().trim()+"',学分='"+fff4.getText().trim()+"' where 课程号='"+fff1.getText().trim()+"'";
sql21=new sql2();
try{aa=sql21.execsql(s);System.out.println("1");
if(aa>0){ System.out.println("2");
JOptionPane.showMessageDialog(this,"成功!"+JOptionPane.WARNING_MESSAGE);
}
}catch(Exception f){f.printStackTrace(); }
}
}
//************************************************************************************************************************
//********************************************************************************************************************
if(e.getSource()==b8 ){
if(ff6.getText().trim().isEmpty()||ff7.getText().trim().isEmpty())
{JOptionPane.showMessageDialog(this,"课程号或学号不得为空!"+JOptionPane.WARNING_MESSAGE);}
else {
// String s="update student set 姓名="+ff2.getText().trim()+","+"性别="+ff3.getText().trim()+","+"年龄="+ff4.getText().trim()+",院系号="+ff3.getText().trim()+"where 学号="+ff1.getText().trim();
// String s="update xuanke set 学号='"+fff1.getText().trim()+"',课程名='"+fff2.getText().trim()+"',先行课='"+fff3.getText().trim()+"',学分='"+fff4.getText().trim()+"' where 课程号='"+fff1.getText().trim()+"'";
String s="update xuanke set 成绩="+ff8.getText().trim()+"where 学号="+ff6.getText().trim()+"and 课程号="+ff7.getText().trim();
sql22=new sql2();
try{aa=sql22.execsql(s);System.out.println("1");System.out.println(aa);
if(aa>0){ System.out.println("2");
JOptionPane.showMessageDialog(this,"修改成功!"+JOptionPane.WARNING_MESSAGE);
}
}catch(Exception f){f.printStackTrace(); }
}
}
//************************************************************************************************************************
if(e.getSource()==b10){if(ff7.getText().trim().isEmpty())
{JOptionPane.showMessageDialog(this,"课程不得为空!"+JOptionPane.WARNING_MESSAGE);}
else {
String s="select 学号,成绩 from xuanke where 课程号="+ff7.getText().trim();
sqll3=new sql();
try{rs3=sqll3.execsql(s); ja4.append("\n"+"学号"+" "+"成绩");
while(rs3.next()){// n++;
ja4.append("\n"+rs3.getString(1)+rs3.getString(2));
// ja2.append("\n"+"该门课选课人数为"+" "+n);
//ja.append("\n");
} rs3.close();
}catch(Exception f){f.printStackTrace(); }
}}
// ************************************************************************************************8
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -