Java Swing+Mysql+beautyEye(介面優美)學校成績管理系統(管理員/學生/教師,資訊管理/選課管理/成績管理)

believe code2life發表於2020-09-25

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 String

                storeUserName = 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 block
					e1.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 block
					e1.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 block
					e1.printStackTrace();
				}
				//ffff.setVisible(true);
				
			} 
             else if (e.getSource() == jMenuItem_jdk_hf) {
				
            	 try {
					Main ffff = new Main(2);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.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 block
			e.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 block
				e.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 block
				e.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 block
				e.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 block
            System.err.println("裝載 JDBC/ODBC 驅動程式失敗。");
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            System.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 block
            e.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 block
            e.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;
	}
	
	@Override
	public 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)

相關文章