📄 mainframe.java~9~
字号:
package sos;
//系统的主类,功能实现的基础
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class MainFrame extends JFrame implements ActionListener, Runnable {
static MainFrame aCheck;
static boolean hasLogIn = false, moveForward = true; //分别标记是否登陆和时间标签是否前移
static String wel = "欢迎使用!请先登录系统!", time = ""; //欢迎String和时间标签
char[] char_Wel = {'欢', '迎', '使', '用', '学', '生', '信', '息', '综', '合',
'查', '询', '管', '理', '系', '统', '!'};
static JLabel jLabel_Wel; //欢迎标签
static long systemTime;
Date date;
static int id = 0, time_x = 0, time_y = 320; //0 for students and 1 for teachers以及时间坐标
static LogIn log; //登陆系统
static ChangePassword changepassword; //更改密码
static InputBasicInfo inputbasicinfo; //基本信息录入
static InputSelectedLessonInfo inputselectedlessoninfo; //选课信息录入
static InputScore inputscore; //成绩信息录入
static BasicInfoCheck basicinfocheck; //基本信息查询
static SelectedLessonInfoCheck selectedlessoninfocheck; //选课信息查询
static LessonInfoCheck lessoninfocheck; //课程信息查询
static ScoreCheck scorecheck; //成绩总查询
static JMenu choice0, choice1, choice2, choice3, choice4;
static JMenuItem m00, m01;
Thread titleThread, timeThread;
public MainFrame() {
super("学生信息综合查询管理系统");
setSize(400, 400);
setResizable(false);
Container content = getContentPane();
content.setBackground(Color.white);
content.setLayout(new BorderLayout());
jLabel_Wel = new JLabel(wel);
jLabel_Wel.setHorizontalAlignment(SwingConstants.
CENTER);
jLabel_Wel.setFont(new Font("华文行楷", Font.BOLD, 30));
content.add(jLabel_Wel);
addWindowListener(new InnerDestroyer());
choice0 = new JMenu("文件");
choice0.setEnabled(true);
JMenuItem m0;
m0 = new JMenuItem("用户登录");
m0.addActionListener(this);
choice0.add(m0);
m0 = new JMenuItem("关于系统");
m0.addActionListener(this);
choice0.add(m0);
m0 = new JMenuItem("系统帮助");
m0.addActionListener(this);
choice0.add(m0);
m01 = new JMenuItem("修改密码");
m01.setEnabled(false);
m01.addActionListener(this);
choice0.add(m01);
m00 = new JMenuItem("注销登录");
m00.setEnabled(hasLogIn);
m00.addActionListener(this);
choice0.add(m00);
m0 = new JMenuItem("退出系统");
m0.addActionListener(this);
choice0.add(m0);
choice1 = new JMenu("信息录入"); //only for teacher
JMenuItem m1;
m1 = new JMenuItem("基本信息录入"); //only for teacher
m1.addActionListener(this);
choice1.add(m1);
m1 = new JMenuItem("选课信息录入"); //only for teacher
m1.addActionListener(this);
choice1.add(m1);
m1 = new JMenuItem("成绩信息录入"); //only for teacher
m1.addActionListener(this);
choice1.add(m1);
m1 = new JMenuItem("信息录入说明"); //only for teacher
m1.addActionListener(this);
choice1.add(m1);
choice2 = new JMenu("统计查询");
JMenuItem m2;
m2 = new JMenuItem("基本信息查询");
m2.addActionListener(this);
choice2.add(m2);
m2 = new JMenuItem("课程信息查询");
m2.addActionListener(this);
choice2.add(m2);
m2 = new JMenuItem("选课信息查询");
m2.addActionListener(this);
choice2.add(m2);
m2 = new JMenuItem("统计查询说明");
m2.addActionListener(this);
choice2.add(m2);
choice3 = new JMenu("成绩查询");
JMenuItem m3;
m3 = new JMenuItem("开始成绩查询");
m3.addActionListener(this);
choice3.add(m3);
m3 = new JMenuItem("成绩查询说明");
m3.addActionListener(this);
choice3.add(m3);
choice4 = new JMenu("系统管理"); //only for the administrator
JMenuItem m4;
m4 = new JMenuItem("管理员登录"); //only for the administrator
m4.addActionListener(this);
choice4.add(m4);
JMenuBar mBar = new JMenuBar();
mBar.setBackground(Color.white);
mBar.add(choice0);
choice1.setEnabled(hasLogIn);
mBar.add(choice1);
choice2.setEnabled(hasLogIn);
mBar.add(choice2);
choice3.setEnabled(hasLogIn);
mBar.add(choice3);
mBar.add(choice4);
setJMenuBar(mBar);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
setVisible(true);
systemTime = System.currentTimeMillis();
date = new Date(systemTime);
time = date.toString();
timeThread = new Thread();
timeThread.start();
titleThread = new Thread(this);
titleThread.start();
}
public void moveTime() {
systemTime = System.currentTimeMillis();
date = new Date(systemTime);
time = date.toString();
if (moveForward) {
if (time_x >= 130) {
moveForward = false;
} else {
time_x += 5;
}
}
if ((!moveForward)) {
if (time_x >= 5) {
time_x -= 5;
} else {
moveForward = true;
}
}
}
public void run() {
while (true) {
try {
Thread.sleep(500);
repaint();
} catch (Exception e) {
}
moveTime();
repaint();
}
}
public void paint(Graphics g) {
this.paintComponents(g);
for (int i = 0; i < char_Wel.length; i++) {
int red = (int) (Math.random() * 255),
blue = (int) (Math.random() * 255),
green = (int) (Math.random() * 255);
g.setFont(new Font("Serif", Font.BOLD, 25));
g.setColor(new Color(red, blue, green));
g.drawChars(char_Wel, i, 1, 5 + 23 * i,
100 + (int) (25 * Math.cos(Math.PI / 4.8 * (i - 1))));
g.setColor(Color.red);
g.setFont(new Font("Serif", Font.BOLD, 20));
g.drawString(time, time_x, time_y + 10);
}
}
public static void logOut() {
hasLogIn = false;
id = 0;
jLabel_Wel.setText(wel);
reset();
}
public static void reset() {
m00.setEnabled(hasLogIn);
m01.setEnabled(hasLogIn);
choice1.setEnabled(id == 1);
choice2.setEnabled(hasLogIn);
choice3.setEnabled(hasLogIn);
}
public static void main(String[] args) {
aCheck = new MainFrame();
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("用户登录")) {
if (hasLogIn == false) {
log = new LogIn(this, true);
} else {
if (JOptionPane.showConfirmDialog(this,
"你已经登录系统!是否重新登陆?单击\"确定\"注销并重新登陆,否则单击\"撤销\"。",
"重新登陆?", 2) ==
0) {
id = 0;
logOut();
log = new LogIn(this, true);
} else {
}
}
}
if (e.getActionCommand().equals("关于系统")) {
JOptionPane.showMessageDialog(this,
"本系统由yanke制作。QQ:251200877,Email:251200877@163.com。\n谢谢使用,欢迎交流沟通!",
"关于系统", 1);
}
if (e.getActionCommand().equals("系统帮助")) {
JOptionPane.showMessageDialog(this,
"本系统主要实现信息录入(仅供教师使用),统计查询,成绩查询及排序等几个功能。\n在每个功能模块内附有相应的使用说明。谢谢使用系统!",
"系统帮助", 1);
}
if (e.getActionCommand().equals("修改密码")) {
changepassword = new ChangePassword(this, true);
}
if (e.getActionCommand().equals("注销登录")) {
int logout = JOptionPane.showConfirmDialog(this,
"确定注销登陆?\n是请单击“确定”,取消请单击“撤销”。",
"退出系统?", 2);
if (logout == 0) {
logOut();
}
}
if (e.getActionCommand().equals("退出系统")) {
int exit = JOptionPane.showConfirmDialog(this,
"确定退出系统?\n是请单击“确定”,取消退出请单击“撤销”。",
"退出系统?", 2);
if (exit == 0) {
System.exit(0);
}
}
if (e.getActionCommand().equals("基本信息录入")) {
inputbasicinfo = new InputBasicInfo(this, true);
}
if (e.getActionCommand().equals("选课信息录入")) {
inputselectedlessoninfo = new InputSelectedLessonInfo(this, true);
}
if (e.getActionCommand().equals("成绩信息录入")) {
inputscore = new InputScore(this, true);
}
if (e.getActionCommand().equals("信息录入说明")) {
JOptionPane.showMessageDialog(this,
"信息录入(教师使用)功能主要实现学生的基本信息,选课信息以及成绩信息的录入。支持每名学生最多选择15门课程。\n谢谢使用!",
"信息录入说明", 1);
}
if (e.getActionCommand().equals("基本信息查询")) {
basicinfocheck = new BasicInfoCheck(this, true);
}
if (e.getActionCommand().equals("课程信息查询")) {
lessoninfocheck = new LessonInfoCheck(this, true);
}
if (e.getActionCommand().equals("选课信息查询")) {
selectedlessoninfocheck = new SelectedLessonInfoCheck(this, true);
}
if (e.getActionCommand().equals("统计查询说明")) {
JOptionPane.showMessageDialog(this,
"统计查询功能主要实现学生的基本信息,选课信息和选课信息的查询。\n谢谢使用!",
"信息录入说明", 1);
}
if (e.getActionCommand().equals("开始成绩查询")) {
if (id == 1) {
scorecheck = new ScoreCheck(this, true);
}
}
if (e.getActionCommand().equals("成绩查询说明")) {
JOptionPane.showMessageDialog(this,
"成绩查询功能主要实现学生的各已选课程的成绩查询。\n谢谢使用!",
"成绩查询说明", 1);
}
if (e.getActionCommand().equals("开始排序查询")) {}
if (e.getActionCommand().equals("成绩排序说明")) {
JOptionPane.showMessageDialog(this,
"排序查询功能主要实现学生的成绩查询,并支持多种排序。\n谢谢使用!",
"排序查询说明", 1);
}
if (e.getActionCommand().equals("管理员登陆")) {
JOptionPane.showMessageDialog(this,
"抱歉,该功能现无法使用。\n谢谢使用!",
"管理员登陆", 1);
}
}
private class InnerDestroyer extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -