📄 mainframe.java~678~
字号:
package prjsystementer;
import java.sql.Connection;
import prjTeacher.*;
import javax.swing.*;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Rectangle;
import prjStudent.CourseFrame;
import prjStudent.StudentInfoFrame;
import prjClassInfo.ClassInfoFrame;
import prjExam.ExamFrame;
import java.util.Date;
import java.util.Date;
import java.util.ArrayList;
import prjUser.UserModel;
import prjUser.User;
import java.awt.Color;
import prjExam.Exam;
import prjExam.ExamModel;
import java.awt.SystemColor;
import java.awt.Font;
public class MainFrame extends JFrame implements Runnable {
JMenuBar mnuAdmin = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenu jMenu2 = new JMenu();
JMenu jMenu3 = new JMenu();
JMenu jMenu4 = new JMenu();
JMenu jMenu5 = new JMenu();
JMenuBar mnuTeacher = new JMenuBar();
JMenu jMenu6 = new JMenu();
JMenu jMenu7 = new JMenu();
JMenu jMenu8 = new JMenu();
JMenu jMenu10 = new JMenu();
JMenu jMenu11 = new JMenu();
JMenu jMenu12 = new JMenu();
JMenuBar mnuStudent = new JMenuBar();
JMenu jMenu13 = new JMenu();
JMenu jMnu14 = new JMenu();
public MainFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
///////////////////////////////////////////////////////////////////////
String userName;
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
JMenuItem jMenuItem5 = new JMenuItem();
JMenuItem jMenuItem6 = new JMenuItem();
JMenuItem jMenuItem7 = new JMenuItem();
JMenuItem jMenuItem8 = new JMenuItem();
JMenuItem jMenuItem9 = new JMenuItem();
JMenuItem jMenuItem10 = new JMenuItem();
JMenuItem jMenuItem12 = new JMenuItem();
JMenuItem jMenuItem13 = new JMenuItem();
JMenuItem jMenuItem14 = new JMenuItem();
JMenuItem jMenuItem15 = new JMenuItem();
JMenu jMenu14 = new JMenu();
JMenuItem jMenuItem16 = new JMenuItem(); //用权限判断
JLabel lblUserName = new JLabel();
JLabel lblTime = new JLabel();
JLabel lblTime2 = new JLabel();
JButton btnRLogin = new JButton();
JButton btnLookStudent = new JButton();
JButton btnLookTeacher = new JButton();
JButton btnAbout = new JButton();
JButton btnLookUserInfo = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JMenu jMenu9 = new JMenu();
JMenuItem jMenuItem11 = new JMenuItem();
JScrollPane panStu = new JScrollPane();
JTable TblStudent = new JTable();
JButton btnUpdateImg = new JButton();
JButton btnImg1 = new JButton();
JButton btnImg2 = new JButton();
JButton btnImg3 = new JButton();
JButton btnCancelTable = new JButton();
JButton btnCancelOk = new JButton();
JScrollPane jScrollPane2 = new JScrollPane();
JLabel lblP2 = new JLabel();
JLabel lblTimeImg = new JLabel();
JLabel lbl1 = new JLabel();
JLabel lbl2 = new JLabel();
JLabel lbl3 = new JLabel();
JLabel lbl4 = new JLabel();
JLabel lbl5 = new JLabel();
JLabel lblAboutOur = new JLabel();
JLabel lbl6 = new JLabel();
JLabel lbl7 = new JLabel();
JLabel lbl8 = new JLabel();
JLabel lbl9 = new JLabel();
JLabel lbl10 = new JLabel();
JLabel lbl11 = new JLabel();
JButton btnCancelAbout = new JButton();
JLabel lblP = new JLabel();
JLabel jLabel1 = new JLabel();
JLabel lblAboutOurImg = new JLabel();
JLabel lblWelecomImg = new JLabel();
public MainFrame(String name) {
this();
this.userName = name;
this.lblUserName.setText("欢迎您:" + userName + "登陆");
int grade = GetGrade(userName);
if (grade == 1) {
this.setJMenuBar(mnuStudent);
//教师和学生登录后不能查看用户信息
this.btnLookUserInfo.setEnabled(false);
//当学生登录后将其第一个按钮设置为查看学生成绩,并赋予快捷键 L .
this.btnLookStudent.setText("查看成绩(L)");
btnLookStudent.setMnemonic('L');
} else if (grade == 2) {
this.setJMenuBar(mnuTeacher);
this.btnLookUserInfo.setEnabled(false);
} else {
this.setJMenuBar(mnuAdmin);
// this.panStu.setVisible(false);
}
}
////////////////////////////////////////////////////////////////////////////
//管理员查看所有用户信息
public void fillUserTable() {
DBManager db = new DBManager();
ResultSet rs = db.ExecuteQuery("select * from T_USERINFO");
ArrayList al = new ArrayList();
try {
while (rs.next()) {
User u = new User();
u.setUserName(rs.getString("userName"));
//u.setPwd(rs.getString("pwd"));
//因为密码涉及用户的 帐号安全,所以将其设置为******
u.setPwd("******");
u.setGrade(rs.getString("grade"));
al.add(u);
}
UserModel um = new UserModel();
um.al = al;
this.TblStudent.setModel(um);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
//////////////////////////////////////////////////////////////////////////
//学生查看自己的成绩
public void fillStudentsTable() {
DBManager db = new DBManager();
ResultSet rs = db.ExecuteQuery("select * from T_EXAM");
ArrayList al = new ArrayList();
try {
while (rs.next()) {
Exam em = new Exam();
em.setExamID(rs.getString("examID"));
em.setStuID(rs.getString("stuID"));
em.setCourseID(rs.getString("courseID"));
em.setWrittenScore(rs.getString("WrittenScore"));
em.setLabScore(rs.getString("LabScore"));
al.add(em);
}
ExamModel tm = new ExamModel();
tm.al = al;
this.TblStudent.setModel(tm);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
///////////////////////////////////////////////////////////////////////////
//所有教师信息
public void fillTeacherTable() {
DBManager db = new DBManager();
ResultSet rs = db.ExecuteQuery("select * from T_TEACHER");
ArrayList al = new ArrayList();
try {
while (rs.next()) {
Teacher tc = new Teacher();
tc.setTeacherID(rs.getString("teacherId"));
tc.setTeacherName(rs.getString("teacherName"));
tc.setTeacherPhone(rs.getString("teacherTel"));
tc.setTeacherMemo(rs.getString("Memo"));
al.add(tc);
}
TeacherModal tm = new TeacherModal();
tm.al = al;
this.TblStudent.setModel(tm);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public int GetGrade(String userName) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cnn = DriverManager.getConnection("jdbc:odbc:test", "sa",
"");
Statement st = cnn.createStatement();
ResultSet rs = st.executeQuery(
"select * from T_USERINFO where userName ='" + userName +
"'");
if (rs.next() == false) {
return 0;
}
int grade = rs.getInt("grade");
return grade;
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
return 0;
}
private Connection DriverManager(String string, String string1,
String string2) {
return null;
}
private void jbInit() throws Exception {
//添加图片
// ImageIcon i = new ImageIcon("F:/房子.jpg"); //"G:/城市夜景.jpg"
// this.lblP.setIcon(i);
//将table初始化为不可见
this.panStu.setVisible(false);
//将table按钮初始化为不可见
this.btnCancelTable.setVisible(false);
//初始化背景按钮不可见
this.btnImg1.setVisible(false);
this.btnImg2.setVisible(false);
this.btnImg3.setVisible(false);
// this.lblP.setOpaque(false);
//在主界面右下角的图片
ImageIcon i = new ImageIcon("F:/纸飞机.gif");
this.lblP2.setIcon(i);
//学生登陆界面的查看成绩前面的图片
// ImageIcon f = new ImageIcon("F:/查询成绩.jpg");
// this.jMnu14.setIcon(f);
// ImageIcon m = new ImageIcon("F:/查询成绩.jpg");
// this.jMenu13.setIcon(m);
ImageIcon f = new ImageIcon("F:/6[7].gif");
this.lblTimeImg.setIcon(f);
//将主界面上的关于标签,和按钮全部初始化为不可见
this.lblAboutOur.setVisible(false);
this.lbl1.setVisible(false);
this.lbl2.setVisible(false);
this.lbl3.setVisible(false);
this.lbl4.setVisible(false);
this.lbl5.setVisible(false);
this.lbl6.setVisible(false);
this.lbl7.setVisible(false);
this.lbl8.setVisible(false);
this.lbl9.setVisible(false);
this.lbl10.setVisible(false);
this.lbl11.setVisible(false);
this.btnCancelAbout.setVisible(false);
//////////////////////////////////////////////////////
//设置关于我们的图片
ImageIcon o = new ImageIcon("F:/关于我们.gif");
this.lblAboutOurImg.setIcon(o);
this.lblAboutOurImg.setVisible(false);
//设置欢迎图片
ImageIcon w = new ImageIcon("F:/欢迎使用.gif");
this.lblWelecomImg.setIcon(w);
//////////////////////////////////////////
jMenu1.setMnemonic('S');
jMenu1.setText("系统(S)");
jMenu2.setMnemonic('U');
jMenu2.setText("用户管理(U)");
jMenu3.setMnemonic('T');
jMenu3.setText("教师管理(T)");
jMenu4.setMnemonic('G');
jMenu4.setText("工具 (G)");
jMenu5.setMnemonic('H');
jMenu5.setText("帮助(H)");
this.getContentPane().setBackground(Color.orange);
this.setForeground(SystemColor.activeCaptionBorder);
this.setJMenuBar(null);
this.setTitle("欢迎登陆 ");
this.setVisible(true);
this.getContentPane().setLayout(null);
jMenu6.setActionCommand("系统管理");
jMenu6.setMnemonic('I');
jMenu6.setText("系统管理(I)");
jMenu7.setMnemonic('M');
jMenu7.setText("学生管理(M)");
jMenu8.setMnemonic('C');
jMenu8.setText("班级管理(C)");
jMenu10.setMnemonic('E');
jMenu10.setText("考试管理(E)");
jMenu11.setMnemonic('T');
jMenu11.setText("其它(T)");
jMenu12.setMnemonic('H');
jMenu12.setText("帮助(H)");
jMenu13.setMnemonic('S');
jMenu13.setText("系统(S)");
jMnu14.setMnemonic('C');
jMnu14.setText("成绩查询(C)");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -