当前位置: 代码迷 >> 综合 >> Java Swing+Mysql+beautyEye(界面优美)学校成绩管理系统(管理员/学生/教师,信息管理/选课管理/成绩管理)
  详细解决方案

Java Swing+Mysql+beautyEye(界面优美)学校成绩管理系统(管理员/学生/教师,信息管理/选课管理/成绩管理)

热度:35   发布时间:2024-02-22 20:32:32.0

Swing学校成绩管理系统

目录

  • Swing学校成绩管理系统
    • 系统功能介绍
    • 主要功能截图
    • 技术点介绍
    • 主要代码说明
    • 写在最后

系统功能介绍

本系统为学校成绩管理系统,目的在于可以让教师更方便、快捷的增添、删除、修改学生的相关信息,让学生能够更加方便的查询自己的选课及课程成绩情况,并且支持管理员的后台信息管理。
(1)用户添加功能,可以在本系统中添加管理员、教师、学生等不同权限级别的用户。
(2)用户登录功能,实现不同权限级别用户的登录。
(3)后台管理,实现学生信息管理、教师信息管理、课程信息管理、年级信息管理、班级信息管理等功能。
(4)选课情况,实现选课录入,选课总览等功能。
(5)成绩管理,实现成绩录入、成绩统计、报表操作等功能。
(6)数据库管理,实现MySQL数据库的初始化操作、数据库备份操作、数据库恢复等功能。

主要功能截图

  1. 登录界面

这里可以选择管理员、学生、教师三种角色登录
2. 管理员界面
管理员登录
3. 后台管理
(包含学生信息、教师信息、课程信息、年级信息、班级信息管理)
学生信息管理
教师信息管理
课程管理
年级信息管理
班级管理

  1. 选课情况
    选课录入
    选课总览

  2. 成绩管理
    成绩录入
    成绩统计
    报表操作

  3. 其他功能
    修改密码
    用户管理
    日志管理
    一键换肤
    使用教程

  4. 学生和教师登录后,只有对应功能的权限
    学生登录
    教师登录

技术点介绍

1> 语言:java swing,即GUI窗口
2> 界面:beautyEye+Bootstrap开源UI框架,使原生的Swing窗口美化很多
3> 数据库:mysql
4> jdk1.7或jdk1.8
5> 特色:使用了背景音乐,在启动系统时即播放
6> 权限分离:管理员、教师、学生三种角色权限操作分离
7> 代码:逻辑清晰,数据库、操作、窗口分离,model、dao、辅助类分类清晰
8> 希望这个代码可以提升你的代码管理能力

项目代码

主要代码说明

1、登录页面布局:Login.java

package com.code2life.student.manage.frame;import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.UIManager;
import java.awt.Rectangle;
import javax.swing.*;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.text.SimpleDateFormat;import javax.swing.JTextField;
import javax.swing.ImageIcon;import com.code2life.student.manage.dao.UserDao;
import com.code2life.student.manage.util.DBConnection;
import com.code2life.student.manage.util.MusicDemo;import javax.swing.JComboBox;
import javax.swing.plaf.InsetsUIResource;import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;public class Login extends JFrame {
    private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private JButton jButton21 = null;private JButton jButton22 = null;private JTextField jTextField = null;private JPasswordField jPasswordField = null;private JLabel jLabel = null;static int storeUserId;// 登录用户名public static String storeUserName = null;// 登录用户名public static String storeUserPassword = null;// 登录密码static boolean RELOAD = true;// 重新登陆标记static int login_user_type;// 0表示管理员,1表示老师,2表示学生private JLabel jLabel_User = null;private JLabel jLabel_userName = null;private JLabel jLabel_password = null;private JLabel jLabel_privilege = null;private URL imgURL = null;private BtnListener btl = null;private JComboBox jComboBox = null;private JLabel jLabel_tips = null;private void initialize() {
    jLabel_tips = new JLabel();jLabel_tips.setBounds(new Rectangle(15, 247, 277, 24));jLabel_tips.setText("管理员使用账号登陆,非管理员请使用ID登陆");this.setResizable(false);this.setSize(296, 356);// this.setSize(350, 450);this.setTitle("欢迎登陆");imgURL = this.getClass().getResource("/com/code2life/student/manage/images/logo_0.png");this.setIconImage(Toolkit.getDefaultToolkit().getImage(imgURL));this.setLocationRelativeTo(null);// this.setUndecorated(true);//设置无边框try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");// 使用windows外观} catch (Exception e) {
    e.printStackTrace();}this.setDefaultCloseOperation(EXIT_ON_CLOSE);jButton21 = new JButton();jButton21.setBounds(new Rectangle(15, 295, 78, 26));/** InputStream in=this.getClass().getResourceAsStream(""); Reader* data=new InputStreamReader(in);*/// 解决打包找不到资源的问题imgURL = this.getClass().getResource("/com/code2life/student/manage/images/icon.png");jButton21.setText("登录");jButton21.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));// 允许回车登录getRootPane().setDefaultButton(jButton21);jButton22 = new JButton();jButton22.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));jButton22.setBounds(new Rectangle(110, 296, 78, 26));jButton22.setText("退出");jTextField = new JTextField(20);jTextField.setBounds(new Rectangle(120, 180, 124, 23));jPasswordField = new JPasswordField();jPasswordField.setBounds(new Rectangle(120, 210, 124, 23));jLabel = new JLabel();jLabel.setText("");jLabel.setBounds(new Rectangle(0, -1, 291, 142));imgURL = this.getClass().getResource("/com/code2life/student/manage/images/login.png");jLabel.setIcon(new ImageIcon(imgURL));jLabel_password = new JLabel();jLabel_password.setBounds(new Rectangle(29, 210, 71, 19));jLabel_password.setText("密 码:");jLabel_userName = new JLabel();jLabel_userName.setBounds(new Rectangle(29, 181, 71, 19));jLabel_userName.setText("用户名:");jLabel_User = new JLabel();jLabel_User.setBounds(new Rectangle(10, 147, 275, 98));jLabel_privilege = new JLabel();jLabel_privilege.setBounds(new Rectangle(18, 272, 71, 19));jLabel_privilege.setText("登陆类型:");jComboBox = new JComboBox();jComboBox.setBounds(new Rectangle(109, 272, 123, 23));jComboBox.addItem("管理登陆");jComboBox.addItem("老师登录");jComboBox.addItem("学生登陆");imgURL = this.getClass().getResource("/com/code2life/student/manage/images/user.gif");jLabel_User.setIcon(new ImageIcon(imgURL));jLabel_User.setText("User");jContentPane = new JPanel();// 新建jPanel面板jContentPane.setLayout(null);// jContentPane.setBackground(new Color(250,250,250));jContentPane.add(jLabel_userName, null);jContentPane.add(jLabel_password, null);jContentPane.add(jButton21, null);jContentPane.add(jButton22, null);jContentPane.add(jTextField, null);jContentPane.add(jPasswordField, null);jContentPane.add(jLabel, null);jContentPane.add(jLabel_User, null);jContentPane.add(jComboBox, null);jContentPane.add(jLabel_privilege, null);jContentPane.add(jLabel_tips, null);setContentPane(jContentPane);btl = new BtnListener();jButton21.addActionListener(btl);jButton22.addActionListener(btl);}/*** @author Administrator* @监听类*/public class BtnListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jButton21) {
    UserDao ud = new UserDao();String user = jTextField.getText().trim();String password = new String(jPasswordField.getPassword()).trim();// char to StringstoreUserName = user;storeUserPassword = password;login_user_type = jComboBox.getSelectedIndex();if ("".equals(user)) {
    JOptionPane.showMessageDialog(null, "用户名不能为空");return;}if ("".equals(password)) {
    JOptionPane.showMessageDialog(null, "密码不能为空");return;}SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dt = sdf.format(new java.util.Date());// 如果是管理员,可以直接使用账户登录if (login_user_type == 0) {
    if (ud.userLogin(login_user_type, storeUserName,storeUserPassword)) {
    dispose();try {
    UIManager.put("RootPane.setupButtonVisible", false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();// 在一键换肤纯色图后加上这一句// BeautyEyeLNFHelper.frameBorderStyle =// BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;// 实心的加上后面这一堆。BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground",Boolean.FALSE);BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();// UIManager.put("RootPane.setupButtonVisible",// false);UIManager.put("TabbedPane.tabAreaInsets",new InsetsUIResource(0, 0, 0, 0));UIManager.put("TabbedPane.contentBorderInsets",new InsetsUIResource(0, 0, 2, 0));UIManager.put("TabbedPane.tabInsets",new InsetsUIResource(3, 10, 9, 10));Font frameTitleFont = (Font) UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont",frameTitleFont);} catch (Exception e1) {
    // TODO exception}MainFrame mf = new MainFrame();mf.setVisible(true);JOptionPane.showMessageDialog(null, "欢迎 " + user+ "登陆!", "关于选修课程管理系统",JOptionPane.INFORMATION_MESSAGE);storeUserId = ud.getUserIdByUserName(storeUserName);String log_operate = "[" + storeUserName + "]"+ "管理员登陆系统";DBConnection.update("insert into c_log(login_user,log_operate,log_time) values('"+ storeUserName+ "','"+ log_operate+ "','" + dt + "')");} else {
    JOptionPane.showMessageDialog(null, "登录失败");return;}// 教师登录} else if (login_user_type == 1) {
    if (ud.userLogin(login_user_type, storeUserName,storeUserPassword)) {
    dispose();MainFrame mf = new MainFrame();mf.setVisible(true);JOptionPane.showMessageDialog(null, "欢迎 "+ storeUserName + "号教师登陆!", "关于选修课程管理系统",JOptionPane.INFORMATION_MESSAGE);String log_operate = "[" + storeUserName + "]号教师"+ "用户登陆系统";DBConnection.update("insert into c_log(login_user,log_operate,log_time) values('"+ storeUserName+ "','"+ log_operate+ "','" + dt + "')");} else {
    JOptionPane.showMessageDialog(null, "登录失败");return;}} else if (login_user_type == 2) {
    System.out.println("学生登录中");System.out.println(login_user_type+","+storeUserName+","+storeUserPassword);if (ud.userLogin(login_user_type, storeUserName,storeUserPassword)) {
    dispose();MainFrame mf = new MainFrame();mf.setVisible(true);JOptionPane.showMessageDialog(null, "欢迎 " + user+ "号学生登陆!", "关于选修课程管理系统",JOptionPane.INFORMATION_MESSAGE);String log_operate = "[" + storeUserName + "]"+ "号学生登陆系统";DBConnection.update("insert into c_log(login_user,log_operate,log_time) values('"+ storeUserName+ "','"+ log_operate+ "','" + dt + "')");} else {
    JOptionPane.showMessageDialog(null, "登录失败");return;}}} else if (e.getSource() == jButton22) {
    System.exit(0);}}}/*** @param args* @throws Exception* @主函数*/public static void main(String[] args) throws Exception {
    try {
    UIManager.put("RootPane.setupButtonVisible", false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);} catch (Exception e) {
    // TODO exception}BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();UIManager.put("RootPane.setupButtonVisible", false);UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0, 0, 0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0, 2, 0));UIManager.put("TabbedPane.tabInsets",new InsetsUIResource(3, 10, 9, 10));Font frameTitleFont = (Font) UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);Login login = new Login(RELOAD);login.setVisible(true);}public Login() {
    super();initialize();}public Login(boolean reload) {
    super();initialize();new MusicDemo();// 背景音乐}
} // @jve:decl-index=0:visual-constraint="10,10"

2.主界面布局:MainFrame.java

package com.code2life.student.manage.frame;import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.plaf.InsetsUIResource;import com.code2life.student.manage.util.About_syjc;
import com.code2life.student.manage.util.DBConnection;
import com.code2life.student.manage.util.DBInit;
import com.code2life.student.manage.util.Main;public class MainFrame extends JFrame {
    private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private JMenu jMenu_start = null;private JMenu jMenu_start2 = null;private JMenuBar jJMenuBar = null;private JMenuBar jJMenuBar2 = null;private JMenu jMenu_backstage  = null;private JMenu jMenu_ccourse = null;private JMenu jMenu_mark = null;private JMenu jMenu_jdk = null;private JMenu jMenu_help = null;private JMenuItem jMenuItem_relogin = null;public  JMenuItem jMenuItem_initDB = null;public  JMenu jMenuItem_hf = null;private JMenuItem jMenuItem_change_password = null;public  JMenuItem jMenuItem_user_manage = null;private JMenuItem jMenuItem_hang_system = null;private JMenuItem jMenuItem_exit = null;private JMenuItem jMenuItem_student_manage = null;private JMenuItem jMenuItem_teacher_manage = null;private JMenuItem jMenuItem_course_manage = null;private JMenuItem jMenuItem_grade_class = null;private JMenuItem jMenuItem_class = null;private JMenuItem jMenuItem_about = null;private JMenuItem jMenuItem_else = null;private JMenuItem jMenuItem_online_update = null;private JMenuItem jm_item0=null;private JMenuItem jm_item1=null;private JMenuItem jm_item2=null;private JMenuItem jm_item3=null;private JMenuItem jm_item4=null;private JMenuItem jMenuItem_sys_info = null;public JMenuItem  jMenuItem_operate_log = null;private JMenuItem jMenuItem_ccourse = null;private JMenuItem jMenuItem_ccourse_add = null;private JMenuItem jMenuItem_mark_add = null;private JMenuItem jMenuItem_bb = null;private JMenuItem jMenuItem_mark_statistics = null;private JMenuItem jMenuItem_jdk_bf = null;private JMenuItem jMenuItem_jdk_hf = null;private JLabel jLabel = null;private JLabel jLabel1 = null;private URL imgURL = null;private URL imgURL1 = null;private SystemTray sysTray = SystemTray.getSystemTray();private int x,y;Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/code2life/student/manage/images/icon.png"));private TrayIcon trayicon = new TrayIcon(image, "成绩管理系统", createMenu());public MainFrame() {
    super();try{
    UIManager.put("RootPane.setupButtonVisible", false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();//在一键换肤纯色图后加上这一句// BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;//实心的加上后面这一堆。BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);}catch(Exception e){
    //TODO exception}initialize(0);initPrivilege();}private void initialize(int tt) {
    		
// //this.setSize(800, 533);// 主界面大小
// //this.setSize(1350,755);
// this.setExtendedState(JFrame.MAXIMIZED_BOTH);this.setTitle("学生成绩管理系统 V1.0");imgURL = this.getClass().getResource("/com/code2life/student/manage/images/icon.png");this.setIconImage(Toolkit.getDefaultToolkit().getImage(imgURL));
// this.setLocationRelativeTo(null);
// this.setResizable(false);
// this.setVisible(true);Toolkit kit = Toolkit.getDefaultToolkit();Dimension dimension = kit.getScreenSize();this.setExtendedState(JFrame.MAXIMIZED_BOTH);this.setBounds(0, 0, dimension.width, dimension.height);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//this.setUndecorated(true);this.setAlwaysOnTop(false);this.setVisible(true);this.addWindowListener(new WindowAdapter()// 系统关闭事件{
    public void windowClosing(WindowEvent e) {
    SystemTrayInitial();//初始化托盘图标}});jMenuItem_relogin = new JMenuItem();jMenuItem_relogin.setText("重新登录");jMenuItem_operate_log = new JMenuItem();jMenuItem_operate_log.setText("操作日志");jMenuItem_change_password = new JMenuItem();jMenuItem_change_password.setText("修改密码");jMenuItem_user_manage = new JMenuItem();jMenuItem_user_manage.setText("用户管理");jMenuItem_initDB = new JMenuItem();jMenuItem_initDB.setText("初始化数据库");jMenuItem_hf = new JMenu();jMenuItem_hf.setText("一键换肤");jMenuItem_hang_system = new JMenuItem();jMenuItem_hang_system.setText("挂机");jMenuItem_exit = new JMenuItem();jMenuItem_exit.setText("退出");jMenuItem_student_manage = new JMenuItem();jMenuItem_student_manage.setText("学生信息管理");jMenuItem_teacher_manage = new JMenuItem();jMenuItem_teacher_manage.setText("教师信息管理");jMenuItem_course_manage = new JMenuItem();jMenuItem_course_manage.setText("课程信息管理");jMenuItem_grade_class = new JMenuItem();jMenuItem_grade_class.setText("年级信息管理");jMenuItem_class = new JMenuItem();jMenuItem_class.setText("班级信息管理");jMenuItem_ccourse_add = new JMenuItem();jMenuItem_ccourse_add.setText("选课录入");jMenuItem_ccourse = new JMenuItem();jMenuItem_ccourse.setText("选课总览");jMenuItem_mark_add = new JMenuItem();jMenuItem_mark_add.setText("成绩录入");jMenuItem_mark_statistics = new JMenuItem();jMenuItem_mark_statistics.setText("成绩统计");jMenuItem_bb = new JMenuItem();jMenuItem_bb.setText("报表操作");jMenuItem_jdk_bf = new JMenuItem();jMenuItem_jdk_bf.setText("数据库备份");jMenuItem_jdk_hf = new JMenuItem();jMenuItem_jdk_hf.setText("数据库恢复");jMenuItem_about = new JMenuItem();jMenuItem_about.setText("关于系统");jMenuItem_sys_info = new JMenuItem();jMenuItem_sys_info.setText("系统说明");jMenuItem_else = new JMenuItem();jMenuItem_else.setText("使用教程");jMenuItem_online_update = new JMenuItem();jMenuItem_online_update.setText("在线升级");jMenu_start = new JMenu();jMenu_start.setText("开始菜单");jMenu_start.add(jMenuItem_relogin);jMenu_start.add(jMenuItem_change_password);jMenu_start.add(jMenuItem_user_manage);jMenu_start.add(jMenuItem_operate_log);jMenu_start.add(jMenuItem_hf);jMenu_start.addSeparator();// 分割线//JMenuItem jm_item0=new JMenuItem("picture0");JMenuItem jm_item1=new JMenuItem("picture1");JMenuItem jm_item2=new JMenuItem("picture2");JMenuItem jm_item3=new JMenuItem("picture3");JMenuItem jm_item4=new JMenuItem("picture4");jMenuItem_hf.add(jm_item0);jMenuItem_hf.add(jm_item1);jMenuItem_hf.add(jm_item2);jMenuItem_hf.add(jm_item3);jMenuItem_hf.add(jm_item4);//JMenuBar jBar=new JMenuBar();//jBar.add(jMenu);//jMenuItem_hf.add(jMenu);//jMenu_start.add(jMenuItem_hang_system);jMenu_start.add(jMenuItem_exit);jMenu_backstage  = new JMenu();jMenu_backstage .setText("后台管理");jMenu_backstage .add(jMenuItem_student_manage);jMenu_backstage .add(jMenuItem_teacher_manage);jMenu_backstage .add(jMenuItem_course_manage);jMenu_backstage .add(jMenuItem_grade_class);jMenu_backstage .add(jMenuItem_class);jMenu_backstage.setForeground(Color.magenta);jMenu_ccourse = new JMenu();jMenu_ccourse.setText("选课情况");jMenu_ccourse.add(jMenuItem_ccourse_add);jMenu_ccourse.add(jMenuItem_ccourse);jMenu_ccourse.setForeground(Color.orange);jMenu_mark = new JMenu();jMenu_mark.setText("成绩管理");jMenu_mark.add(jMenuItem_mark_add);jMenu_mark.add(jMenuItem_mark_statistics);jMenu_mark.add(jMenuItem_bb);//jMenu_mark.setFont(new Font("宋体",Font.PLAIN,16));jMenu_mark.setForeground(Color.blue);jMenu_jdk = new JMenu();jMenu_jdk.setText("数据库管理");jMenu_jdk.add(jMenuItem_initDB);jMenu_jdk.add(jMenuItem_jdk_bf);jMenu_jdk.add(jMenuItem_jdk_hf);jMenu_jdk.setForeground(Color.green);jMenu_help = new JMenu();jMenu_help.setText("帮助");jMenu_help.add(jMenuItem_about);jMenu_help.add(jMenuItem_sys_info);jMenu_help.add(jMenuItem_else);//jMenu_help.add(jMenuItem_online_update);jJMenuBar = new JMenuBar();jJMenuBar.setPreferredSize(new Dimension(10, 25));jJMenuBar.add(jMenu_start);jJMenuBar.add(jMenu_backstage );jJMenuBar.add(jMenu_ccourse);jJMenuBar.add(jMenu_mark);jJMenuBar.add(jMenu_jdk);jJMenuBar.add(jMenu_help);//jJMenuBar.setForeground(Color.red);jJMenuBar.setBackground(Color.getHSBColor(192,220,243));setJMenuBar(jJMenuBar);jLabel = new JLabel();//jLabel.setText("JLabel");//jLabel.setBounds(new Rectangle(1, -2, 1600, 768));x=dimension.width;y=dimension.height;jLabel.setBounds(0, 0, dimension.width, dimension.height);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main.jpg");jLabel.setIcon(new ImageIcon(imgURL));jContentPane = new JPanel();//jContentPane.add(jLabel1, null);jContentPane.setLayout(null);jContentPane.add(jLabel, null);setContentPane(jContentPane);btnListener btn = new btnListener();jMenuItem_relogin.addActionListener(btn);jMenuItem_change_password.addActionListener(btn);jMenuItem_user_manage.addActionListener(btn);jMenuItem_initDB.addActionListener(btn);jMenuItem_operate_log.addActionListener(btn);jMenuItem_hang_system.addActionListener(btn);jMenuItem_exit.addActionListener(btn);jMenuItem_student_manage.addActionListener(btn);jMenuItem_teacher_manage.addActionListener(btn);jMenuItem_course_manage.addActionListener(btn);jMenuItem_grade_class.addActionListener(btn);jMenuItem_class.addActionListener(btn);jMenuItem_ccourse_add.addActionListener(btn);jMenuItem_about.addActionListener(btn);jMenuItem_else.addActionListener(btn);jMenuItem_mark_add.addActionListener(btn);jMenuItem_mark_statistics.addActionListener(btn);jMenuItem_bb.addActionListener(btn);jMenuItem_jdk_bf.addActionListener(btn);jMenuItem_jdk_hf.addActionListener(btn);jMenuItem_ccourse.addActionListener(btn);jMenuItem_sys_info.addActionListener(btn);jm_item0.addActionListener(btn);jm_item1.addActionListener(btn);jm_item2.addActionListener(btn);jm_item3.addActionListener(btn);jm_item4.addActionListener(btn);jm_item0.setActionCommand("000");jm_item1.setActionCommand("111");jm_item2.setActionCommand("222");jm_item3.setActionCommand("333");jm_item4.setActionCommand("444");}
/*** @初始化托盘*/private void SystemTrayInitial() {
     // 托盘if (!SystemTray.isSupported()) // 判断当前系统是否支持系统栏return;try {
    sysTray.add(trayicon);} catch (AWTException e1) {
    e1.printStackTrace();}setVisible(false);trayicon.displayMessage("选课管理系统--By axuhongbo and his friends", "选课管理系统", MessageType.INFO);// 窗体托盘时所显示的消息对话trayicon.addActionListener(new ActionListener()// 击图标时显示窗体{
    public void actionPerformed(ActionEvent e) {
    sysTray.remove(trayicon);setVisible(true);}});}
/*** @初始化托盘右键* @return*/private PopupMenu createMenu() {
     // 创建系统栏菜单的方法PopupMenu menu = new PopupMenu();MenuItem exitItem = new MenuItem("退出本系统");exitItem.addActionListener(new ActionListener() {
     // 系统栏退出事件public void actionPerformed(ActionEvent e) {
    System.exit(0);}});MenuItem openItem = new MenuItem("打开主窗口");openItem.addActionListener(new ActionListener() {
    // 系统栏打开菜单项事件public void actionPerformed(ActionEvent e) {
    if (!isVisible()) {
    setVisible(true);sysTray.remove(trayicon);}}});MenuItem viewItem = new MenuItem("你好");viewItem.addActionListener(new ActionListener() {
    // 系统栏打开菜单项事件public void actionPerformed(ActionEvent e) {
    try {
    Runtime.getRuntime().exec("explorer http://axuhongbo.top");} catch (IOException e1) {
    e1.printStackTrace();}}});menu.add(openItem);menu.add(viewItem);menu.addSeparator();menu.add(exitItem);return menu;}public void initPrivilege(){
    if(Login.login_user_type==1){
    jMenuItem_change_password.setEnabled(false);jMenuItem_operate_log.setEnabled(false);jMenuItem_initDB.setEnabled(false);jMenuItem_user_manage.setEnabled(false);jMenu_backstage .setEnabled(false);jMenu_jdk.setEnabled(false);}else if(Login.login_user_type==0){
    			}else if(Login.login_user_type==2){
    jMenuItem_change_password.setEnabled(true);jMenuItem_operate_log.setEnabled(false);jMenuItem_initDB.setEnabled(false);jMenuItem_user_manage.setEnabled(false);jMenuItem_sys_info.setEnabled(false);jMenu_mark.setEnabled(false);jMenu_backstage .setEnabled(false);jMenu_jdk.setEnabled(false);}else{
    jMenuItem_change_password.setEnabled(false);jMenuItem_operate_log.setEnabled(false);jMenuItem_initDB.setEnabled(false);jMenuItem_user_manage.setEnabled(false);jMenuItem_sys_info.setEnabled(false);jMenu_mark.setEnabled(false);jMenu_backstage .setEnabled(false);jMenu_jdk.setEnabled(false);}}public class btnListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jMenuItem_relogin) {
    dispose();Login login = new Login();// 调用无参数构造方法,避免音乐重复播放login.setVisible(true);} else if (e.getSource() == jMenuItem_change_password) {
    
// if(Login.login_user_type!=0)
// {JOptionPane.showMessageDialog(null, "对不起,非后台管理员暂不提供修改密码功能");
// return;
// }UserChangePassword cp = new UserChangePassword();cp.setVisible(true);} else if (e.getSource() == jMenuItem_user_manage) {
    UserManage um = new UserManage();um.setVisible(true);} else if (e.getSource() == jMenuItem_operate_log) {
    LogManage lm = new LogManage();lm.setVisible(true);} else if (e.getActionCommand().equals("000")) {
    jLabel.setBounds(0, 0, x, y);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main.jpg");jLabel.setIcon(new ImageIcon(imgURL));try{
    BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);}catch(Exception ee){
    //TODO exception}} else if (e.getActionCommand().equals("111")) {
    jLabel.setBounds(0, 0, x, y);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main1.jpg");jLabel.setIcon(new ImageIcon(imgURL));try{
    BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);}catch(Exception ee){
    //TODO exception}} else if (e.getActionCommand().equals("222")) {
    jLabel.setBounds(0, 0, x, y);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main2.jpg");jLabel.setIcon(new ImageIcon(imgURL));BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;try {
    BeautyEyeLNFHelper.launchBeautyEyeLNF();} catch (Exception e1) {
    // TODO Auto-generated catch blocke1.printStackTrace();}BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);} else if (e.getActionCommand().equals("333")) {
    jLabel.setBounds(0, 0, x, y);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main3.jpg");jLabel.setIcon(new ImageIcon(imgURL));try{
    BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);}catch(Exception ee){
    //TODO exception}} else if (e.getActionCommand().equals("444")) {
    jLabel.setBounds(0, 0, x, y);imgURL = this.getClass().getResource("/com/code2life/student/manage/images/main4.jpg");jLabel.setIcon(new ImageIcon(imgURL));BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;try {
    BeautyEyeLNFHelper.launchBeautyEyeLNF();} catch (Exception e1) {
    // TODO Auto-generated catch blocke1.printStackTrace();}BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);} else if (e.getSource() == jMenuItem_hang_system) {
    DBConnection.update(Login.storeUserName + " 执行挂机操作!");JOptionPane.showMessageDialog(null, "暂未考虑加入挂机功能!");} else if (e.getSource() == jMenuItem_initDB) {
    DBInit di = new DBInit();di.setVisible(true);} else if (e.getSource() == jMenuItem_exit) {
    System.exit(0);} else if (e.getSource() == jMenuItem_student_manage) {
    StudentManage sm = new StudentManage();sm.setVisible(true);} else if (e.getSource() == jMenuItem_teacher_manage) {
    TeacherManage tm = new TeacherManage();tm.setVisible(true);}else if (e.getSource() == jMenuItem_grade_class) {
    //JOptionPane.showMessageDialog(null, "功能优化中...敬请期待!");GradeManage gm = new GradeManage();gm.setVisible(true);} else if(e.getSource() == jMenuItem_class){
    ClassManage cm= new ClassManage();cm.setVisible(true);//JOptionPane.showMessageDialog(null, "功能优化中...敬请期待!");}else if (e.getSource() == jMenuItem_course_manage) {
    CourseManage cm = new CourseManage();cm.setVisible(true);} else if (e.getSource() == jMenuItem_ccourse_add) {
    CCourseAdd cm = new CCourseAdd();cm.setVisible(true);} else if (e.getSource() == jMenuItem_ccourse) {
    CCourseManage cci = new CCourseManage();cci.setVisible(true);}else if (e.getSource() == jMenuItem_mark_add) {
    CCourseMarkAdd ccma = new CCourseMarkAdd();ccma.setVisible(true);}else if (e.getSource() == jMenuItem_mark_statistics) {
    CCourseMarkStatistic ccs = new CCourseMarkStatistic();ccs.setVisible(true);} else if (e.getSource() == jMenuItem_bb) {
    CCourse_bb ds = new CCourse_bb();ds.setVisible(true);} else if (e.getSource() == jMenuItem_jdk_bf) {
    try {
    Main sjk = new Main(1);} catch (IOException e1) {
    // TODO Auto-generated catch blocke1.printStackTrace();}//ffff.setVisible(true);} else if (e.getSource() == jMenuItem_jdk_hf) {
    try {
    Main ffff = new Main(2);} catch (IOException e1) {
    // TODO Auto-generated catch blocke1.printStackTrace();}}else if (e.getSource() == jMenuItem_about) {
    About ab = new About();ab.setVisible(true);} else if(e.getSource() == jMenuItem_else){
    About_syjc abs= new About_syjc(); abs.setVisible(true);}
// else if (e.getSource() == jMenuItem_else) {
    
// About ab = new About();
// ab.setVisible(true);
// } else if (e.getSource() == jMenuItem_sys_info) {
    try {
    String fp = System.getProperty("user.dir") + "\\readme.txt";File f = new File(fp);if (f.exists()) {
    Runtime.getRuntime().exec(" notepad.exe " + fp);} else {
    JOptionPane.showMessageDialog(null, "http://www.code2life.wang/stu/");}} catch (Exception e1) {
    e1.printStackTrace();}}}}public static void main(String[] args) {
    try{
    UIManager.put("RootPane.setupButtonVisible", false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();//在一键换肤纯色图后加上这一句// BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;//实心的加上后面这一堆。BeautyEyeLNFHelper.translucencyAtFrameInactive = false;UIManager.put("ToolBar.isPaintPlainBackground", Boolean.FALSE);BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;BeautyEyeLNFHelper.launchBeautyEyeLNF();// UIManager.put("RootPane.setupButtonVisible", false); UIManager.put("TabbedPane.tabAreaInsets", new InsetsUIResource(0,0,0,0));UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0,0,2,0));UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(3,10,9,10));Font frameTitleFont = (Font)UIManager.get("InternalFrame.titleFont");frameTitleFont = frameTitleFont.deriveFont(Font.PLAIN);UIManager.put("InternalFrame.titleFont", frameTitleFont);}catch(Exception e){
    //TODO exception}MainFrame login = new MainFrame();login.setVisible(true);}}

3.用户管理dao: UserDao.java

package com.code2life.student.manage.dao;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import com.code2life.student.manage.model.UserModel;
import com.code2life.student.manage.util.DBConnection;public class UserDao {
    /*** 用户登录login_user_type 为0表示管理,为1表示教师,为2表示学生* @param login_user_type* @param user_name ,如果是学生,使用id登录* @param password* @return*/public boolean userLogin(int login_user_type,String user_name,String password){
    String sql = "";switch(login_user_type){
    case 0://管理员登录sql = "select * from c_user where user_name='" + user_name+ "' and user_password='" + password + "'";break;case 1://教师登录sql = "select * from c_teacher where teach_id=" + user_name+ " and teach_password='" + password + "'";break;case 2://学生使用id登录
// sql = "select * from c_student where stu_id=" + user_name+ " and stu_password='" + password + "'";sql = "select * from c_student where stu_name='" + user_name+ "' and stu_password='" + password + "'";System.out.println(sql);break;}try {
    ResultSet rs = DBConnection.query(sql);if(rs.next()){
    rs.close();return true;}} catch (SQLException e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return false;}public List<UserModel> getLists(boolean option,int teach_id){
    List<UserModel> lists = new ArrayList<UserModel>();String sql = "";if(option){
    sql = "select * from c_user where user_id="+teach_id;}else{
    sql = "select * from c_user";}ResultSet rs = DBConnection.query(sql);try {
    while(rs.next()){
    UserModel um = new UserModel();um.setUser_id(rs.getInt("user_id"));um.setUser_name(rs.getString("user_name"));um.setUser_login_ip(rs.getString("user_login_ip"));um.setUser_login_time(rs.getString("user_login_time"));um.setUser_password(rs.getString("user_password"));um.setUser_privilege(rs.getString("user_privilege"));lists.add(um);				}rs.close();} catch (SQLException e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return lists;}/*** @删除用户* @param user_id* @return*/public boolean deleteListByUserId(int user_id){
    String sql ="delete from c_user where user_id="+user_id;return (DBConnection.update(sql))?true:false;}/*** @添加用户* @param user_name* @param user_password* @param user_privilege* @return*/public boolean addUser(String user_name,String user_password,String user_privilege){
    String sql = "insert into c_user(user_name,user_password,user_privilege) values('"+user_name+"','"+user_password+"','"+user_privilege+"')";return DBConnection.update(sql)==true?true:false;}/*** @修改用户* @param user_name* @param user_password* @param user_privilege* @return*/public boolean modifyUser(String user_name,String user_password,String user_privilege){
    String sql = "update c_user set user_name='"+user_name+"',user_password='"+user_password+"',user_privilege='"+user_privilege+"'";return DBConnection.update(sql)==true?true:false;}/*** @修改密码* @param option 值为0表示修改管理员,1修改老师,2修改学生* @param name_or_id 学生或管理员id* @param old_password* @param new_password* @return*/public boolean changeUserPassword(int option,String name_or_id,String old_password,String new_password){
    String sql = "";if(option==0){
    sql = "update c_user set user_password = '"+new_password+"' where user_name ='"+name_or_id+"' and user_password='"+old_password+"'";}else if(option==2){
    sql = "update c_student set student_password='"+new_password+"' where student_id="+name_or_id;}return DBConnection.update(sql)==true?true:false;}/*** @检查用户是否重名 * @param user_name* @return 返回true 表示存在重名*/public boolean isExist(String user_name){
    String sql = "select * from c_user where user_name='"+user_name+"'";ResultSet rs = DBConnection.query(sql);try {
    if(rs.next()){
    rs.close();return true;}} catch (SQLException e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return false;}/*** @根据用户名找出id* @param user_name* @return*/public int getUserIdByUserName(String user_name){
    int user_id=0;String sql = "select user_id from c_user where user_name='"+user_name+"'";ResultSet rs = DBConnection.query(sql);try {
    if(rs.next()){
    user_id = rs.getInt("user_id");}rs.close();} catch (SQLException e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return user_id;}}

其他模块dao与这个逻辑都差不多的,模仿写既可

4.数据库连接辅助类:DbHelper.java

package com.code2life.javen.db;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class DBhepler {
    /*String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";String url = "jdbc:sqlserver://127.0.0.1;DatabaseName=Mobile";*/String driver = "com.mysql.jdbc.Driver";String url = "jdbc:mysql://127.0.0.1:3306/studentmanager?useUnicode=true&characterEncoding=utf-8";Connection con = null;ResultSet res = null;public void DataBase() {
    try {
    Class.forName(driver);con = DriverManager.getConnection(url, "root", "");} catch (ClassNotFoundException e) {
    // TODO Auto-generated catch blockSystem.err.println("装载 JDBC/ODBC 驱动程序失败。");e.printStackTrace();} catch (SQLException e) {
    // TODO Auto-generated catch blockSystem.err.println("无法连接数据库");e.printStackTrace();}}// 查询public ResultSet Search(String sql, String str[]) {
    DataBase();try {
    PreparedStatement pst = con.prepareStatement(sql);if (str != null) {
    for (int i = 0; i < str.length; i++) {
    pst.setString(i + 1, str[i]);}}res = pst.executeQuery();} catch (Exception e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return res;}// 增删修改public int AddU(String sql, String str[]) {
    int a = 0;DataBase();try {
    PreparedStatement pst = con.prepareStatement(sql);if (str != null) {
    for (int i = 0; i < str.length; i++) {
    pst.setString(i + 1, str[i]);}}a = pst.executeUpdate();} catch (Exception e) {
    // TODO Auto-generated catch blocke.printStackTrace();}return a;}}

5.学生实体类封装:StuEntity.java

public class StuEntity {
    private int id;private String name;private String sex;private int num;public StuEntity() {
    }public StuEntity(int id, String name, String sex, int num) {
    this.id = id;this.name = name;this.sex = sex;this.num = num;}@Overridepublic String toString() {
    return "StuEntity [id=" + id + ", name=" + name + ", sex=" + sex+ ", num=" + num + "]";}public int getId() {
    return id;}public void setId(int id) {
    this.id = id;}public String getName() {
    return name;}public void setName(String name) {
    this.name = name;}public String getSex() {
    return sex;}public void setSex(String sex) {
    this.sex = sex;}public int getNum() {
    return num;}public void setNum(int num) {
    this.num = num;}}

6.其他就是存放图片、报表、声音等的文件啦,代码的结构大概是这样子

写在最后

这个系统耗费心血较大,功能点也比较多,可能有点小bug,但是基本的功能都可以完美使用。(如需完整源码Q:3459067873)

  相关解决方案