@TOC

Swing+mysql的校园管理系统

本系统综合了校园管理的所有功能,一共分为三个角色:学生、教师、管理员端。对应的功能有:学生管理、教师管理、用户管理、班级管理、成绩管理、专业管理、点名考勤系统、留言管理、校园通信,另外有休闲游戏、音乐系统等。

实现功能截图

登录
请添加图片描述

学生管理
请添加图片描述
教师管理
请添加图片描述
班级管理
请添加图片描述
成绩管理
请添加图片描述
个人信息
请添加图片描述
角色管理
请添加图片描述
课程管理:
请添加图片描述
留言管理
请添加图片描述
校园通信
请添加图片描述
宿舍管理
请添加图片描述
点名签到系统
请添加图片描述
请添加图片描述
专业管理
请添加图片描述
休闲小游戏
请添加图片描述
音乐系统
请添加图片描述

系统功能

角色:
学生、教师、管理员
本学院管理系统实现了以下功能:
1、学生管理
2、教师管理
3、用户管理
4、专业管理
5、课程管理
6、专业管理
7、班级管理
8、成绩管理
9、个人信息
10、留言管理
11、点名系统
12、角色管理
13、音乐系统
14、休闲小游戏

使用技术

数据库:mysql
开发工具:Eclipse(Myeclispe、Idea也可以)
知识点:swing

代码

实体类
校园通信:
Client.java

/*
 * Client.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.cssve.chat;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.com.zh.entity.User;
import cn.com.zh.ui.MainFrame;

public class Client extends javax.swing.JFrame {

    Socket socket;
    String clientName;

    private PrintWriter out;
    User u;
    public Client(Socket socket, String name,User u) {
        this.socket = socket;
        this.clientName = name;
        this.u=u;
        setTitle("欢迎【" + name + "】来到无聊【聊天室】");
        initComponents();
        new ChatThread(socket).start();

        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                setVisible(false);
            }
        });
    }

    //会话层
    class ChatThread extends Thread {
        private Socket socket;

        public ChatThread(Socket socket) {
            this.socket = socket;
        }

        @Override
        public void run() {
            try {
                out = new PrintWriter(socket.getOutputStream(), true);
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        socket.getInputStream()));
                new GetThread(br).start();
                out.println(clientName);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //获取信息
    class GetThread extends Thread {
        private BufferedReader br;

        public GetThread(BufferedReader br) {
            this.br = br;
        }

        @Override
        public void run() {
            try {
                while (true) {
                    String msg = br.readLine();
                    System.out.println(msg);
                    //判断服务器是否已经关闭,或者被踢出来
                    if (msg == null) {
                        break;
                    }
                    if (msg.startsWith("list:")) {
                        DefaultListModel dlm = new DefaultListModel();
                        String list = msg.substring(5);
                        StringTokenizer st = new StringTokenizer(list, "[,]");
                        System.out.println(st);
                        while (st.hasMoreTokens()) {
                            dlm.addElement(st.nextToken());
                        }
                        jList1_user.setModel(dlm);
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat(
                                "yyyy年MM月dd日  HH:mm:ss");
                        String getTime = sdf.format(new Date());
                        jTextArea1.append(getTime+"\n"+msg + "\n");
                    }
                }
            } catch (IOException e) {
            } finally {
                JOptionPane
                        .showMessageDialog(
                                null,
                                "<html>与主机失去联系!发生错误的原因可能有:<br>①您的昵称已经存在,请更改<br>②服务器已经关闭,请等待服务器重新启动<br>③您被管理员踢出来了!请注意遵守聊天室规则</html>");
//              new ChatLoginInterface().setVisible(true);
                Client.this.dispose();
            }

        }
    }

    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1_user = new javax.swing.JList(new DefaultListModel<>());
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jTextField_import = new javax.swing.JTextField();
jButton_send = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 255, 204));

jList1_user.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0), "\u7528\u6237\u5217\u8868", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 14)));
jList1_user.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jList1_user.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
jScrollPane1.setViewportView(jList1_user);

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane2.setViewportView(jTextArea1);

jButton_send.setText("\u53d1  \u9001");
jButton_send.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_sendActionPerformed(evt);
}
});

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "群      聊", "私      聊" }));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jTextField_import, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton_send)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane2)))
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField_import, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton_send)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(31, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}
    //点击发送按钮
    private void jButton_sendActionPerformed(java.awt.event.ActionEvent evt) {
        String text = jTextField_import.getText().trim();
        //在下一次输入的时候将输入框清空
        jTextField_import.setText("");
        if (text.equals("")) {
            JOptionPane.showMessageDialog(null, "发送的消息不能为空,请输入内容之后再发送!");
        }else{
            // 获得发送消息的类型
            int index=jComboBox1.getSelectedIndex();
            if (index==0) {//群聊
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
                String getTime = sdf.format(new Date());
                out.println(clientName + ":all:" + text);
//              jTextArea1.append(getTime+"\n"+clientName+"对所有人说:"+text+"\n");
            }else{//私聊
                int item = jList1_user.getSelectedIndex();
                if (item==-1) {
                   JOptionPane.showMessageDialog(null, "私聊必须选择一个用户");
                }else{
                    String name = jList1_user.getSelectedValue().toString();
                    if (name.equals(clientName)) {
                         JOptionPane.showMessageDialog(null, "您不能和自己私聊");
                         jTextField_import.setText("");
                    }else{
                        SimpleDateFormat sdf = new SimpleDateFormat(
                                "yyyy年MM月dd日  HH:mm:ss");
                        String getTime = sdf.format(new Date());
                    jTextArea1.append(getTime+"\n"+clientName + "对" + name + "说:"+text);
                    out.println(clientName + ":" + item + ":" + text);
                    }
                }
            }
        }
    }

    //  public static void main(String args[]) {
    //      java.awt.EventQueue.invokeLater(new Runnable() {
    //          public void run() {
    ////                new Client().setVisible(true);
    //          }
    //      });
    //  }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton_send;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JList jList1_user;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField_import;
    // End of variables declaration//GEN-END:variables

}

ServerFrame.java

/*
 * ServerFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.cssve.chat;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.com.zh.entity.User;
import cn.com.zh.ui.MainFrame;
import cn.com.zh.util.TimeUtil;

/**
 *
 * @author  __USER__
 */
public class ServerFrame extends javax.swing.JFrame implements ActionListener,KeyListener {

    /** Creates new form ServerFrame */

    TimeUtil timeUtil = new TimeUtil();
    String time = TimeUtil.getTime();
    User p;
    public ServerFrame(final User user) {
        initComponents();
        setLocationRelativeTo(null);
        jButton4.addActionListener(this);
        createFile();
        this.setFocusable(true);
        this.addKeyListener(this);

        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                setVisible(false);
            }
        });
    }

    private void createFile() {
        try {
            String newPath = System.getProperty("user.dir");
            dir = newPath + "\\记录\\" + time;
            fileDir = new File(dir);
            System.out.println(fileDir.getAbsolutePath());
            if (!fileDir.isDirectory()) {
                fileDir.mkdirs();
            }
            fileName = "聊天记录.txt";
            bw = new BufferedWriter(new FileWriter(dir + "\\" + fileName, true));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jButton_initiator = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList_user = new javax.swing.JList(new DefaultListModel<>());
jLabel_sate = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton_kick = new javax.swing.JButton();
jButton_send = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
jTextField_import = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u670d\u52a1\u5668");
setResizable(false);

jPanel1.setBackground(new java.awt.Color(204, 255, 204));

jButton_initiator.setFont(new java.awt.Font("楷体", 1, 18));
jButton_initiator.setText("\u542f\u52a8\u670d\u52a1\u5668");
jButton_initiator.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_initiatorActionPerformed(evt);
}
});

jList_user.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0), "\u7528\u6237\u5217\u8868", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 18)));
jList_user.setFont(new java.awt.Font("楷体", 0, 14));

jScrollPane1.setViewportView(jList_user);

jLabel_sate.setFont(new java.awt.Font("楷体", 1, 14));
jLabel_sate.setForeground(new java.awt.Color(255, 0, 51));
jLabel_sate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel_sate.setText("\u5173\u95ed");
jLabel_sate.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "\u670d\u52a1\u5668\u72b6\u6001", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 24), new java.awt.Color(0, 204, 204)));

jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setRows(5);
jScrollPane2.setViewportView(jTextArea1);

jButton_kick.setFont(new java.awt.Font("楷体", 1, 14));
jButton_kick.setText("\u8e22\u51fa\u7528\u6237");
jButton_kick.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_kickActionPerformed(evt);
}
});

jButton_send.setFont(new java.awt.Font("楷体", 1, 14));
jButton_send.setText("\u53d1 \u9001");
jButton_send.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_sendActionPerformed(evt);
}
});

jButton3.setFont(new java.awt.Font("楷体", 1, 14));
jButton3.setText("\u6e05\u9664\u804a\u5929\u8bb0\u5f55");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setFont(new java.awt.Font("楷体", 1, 14));
jButton4.setText("\u4fdd\u5b58\u804a\u5929\u8bb0\u5f55");

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "群      聊", "私      聊" }));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton_initiator, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton_kick)
.addGap(18, 18, 18)))
.addGap(58, 58, 58)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(28, 28, 28)
.addComponent(jButton4)
.addGap(51, 51, 51))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jTextField_import, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton_send)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton4))
.addGap(27, 27, 27))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel_sate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jButton_initiator, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel_sate, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton_send)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField_import, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jButton_kick))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3)
.addComponent(jButton4)
.addComponent(jButton4))))
.addGap(18, 18, 18))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

    //GEN-END:initComponents
    //清空聊天记录
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        int i = JOptionPane.showConfirmDialog(this, "你确定要清空聊天信息吗?", "提  示",
                JOptionPane.OK_CANCEL_OPTION);
        if (i == JOptionPane.OK_OPTION) {
            jTextArea1.setText("");
        } else {
            JOptionPane.showMessageDialog(null, "聊条信息清空失败!", "提  示",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }

    //踢出用户
    protected void jButton_kickActionPerformed(ActionEvent evt) {
        Object object = jList_user.getSelectedValue();
        if (object != null) {
            ClientBean cb = (ClientBean) object;
            ((DefaultListModel) jList_user.getModel()).removeElement(cb);
            try {
                cb.getSocket().close();
            } catch (IOException e) {
            } finally {
                String msg = "管理员将【" + cb.clientName + "】赶出聊天室";
                sendAll(msg);
                sendList();
            }
        } else {
            JOptionPane.showMessageDialog(null, "请从用户列表选择您要踢出的人");
        }

    }

    private void jButton_sendActionPerformed(ActionEvent evt) {
        String imp = jTextField_import.getText().trim();
        jTextField_import.setText("");
        if (imp.equals("")) {
            JOptionPane.showMessageDialog(null, "发送的信息不能为空");
        } else {
            //获得发送信息的类型
            int index = jComboBox1.getSelectedIndex();
            //索引0代表群聊
            if (index == 0) {
                String msg = "管理员对说有人说:" + imp;
                sendAll(msg);

            } else {
                Object obj = jList_user.getSelectedValue();
                if (obj == null) {
                    JOptionPane.showMessageDialog(null, "私聊必须选择一个用户");
                } else {
                    ClientBean cb = (ClientBean) obj;
                    String msg = "管理员对【" + cb.getClientName() + "】说:" + imp;
                    sendPrivate(msg, cb);
                }
            }
        }

    }

    // 启动服务器
    private void jButton_initiatorActionPerformed(java.awt.event.ActionEvent evt) {
        String text = jButton_initiator.getText();
        if (text.equals("启动服务器")) {
            startServer();
        } else {
            stopServer();
        }

    }

    public static int Post = 2002;
    public boolean flag = false;

    // 启动服务器
    private void startServer() {
        try {
            flag = true;
            socket = new ServerSocket(Post);
            jLabel_sate.setText("服务器正在监听" + Post + "端口");
            jButton_initiator.setText("关闭服务器");
            new ListenerThread().start();
        } catch (IOException e) {
            JOptionPane.showMessageDialog(this, "服务器启动失败!");
        }

    }

    //监听线程
    class ListenerThread extends Thread {
        @Override
        public void run() {
            while (flag) {
                try {
                    Socket accp = socket.accept();
                    //启动与客户端会话线程
                    new chatThread(accp).start();
                } catch (IOException e) {
                    flag = false;
                }

            }
        }
    }

    //客户端会话线程
    class chatThread extends Thread {
        private Socket s;

        public chatThread(Socket s) {
            this.s = s;
        }

        @Override
        public void run() {
            try {
                PrintWriter out = new PrintWriter(s.getOutputStream(), true);
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        s.getInputStream()));
                //获得客户端昵称
                String clientName = br.readLine();
                //            System.out.println(clientName);
                if (existsClientName(clientName)) {
                    s.close();
                } else {
                    ClientBean cb = new ClientBean(s, clientName, out);
                    DefaultListModel dlm = (DefaultListModel) jList_user
                            .getModel();
                    //将客户端添加到ServerControl界面
                    dlm.addElement(cb);
                    //欢迎词
                    String welcome = "欢迎【" + clientName + "】来到【无聊】聊天室";
                    //向各客户端发送欢迎词
                    sendAll(welcome);
                    //向客户端发送用户列表
                    sendList();
                    //启动获得客户端信息线程
                    new GetThread(br, cb).start();
                }
            } catch (IOException e) {
            }
        }

        //获取客户端信息
        class GetThread extends Thread {
            private BufferedReader br;
            private ClientBean cb;

            public GetThread(BufferedReader br, ClientBean cb) {
                this.br = br;
                this.cb = cb;
            }

            @Override
            public void run() {
                try {
                    while (true) {
                        String text = br.readLine();
                        String[] content = text.split(":");
                        if (content[1].equals("all")) {
                            String msg = content[0] + "对所有人说:" + content[2];
                            sendAll(msg);
                        } else {
                            int index = Integer.parseInt(content[1]);
                            Object object = jList_user.getModel().getElementAt(
                                    index);
                            if (object != null) {
                                ClientBean cb = (ClientBean) object;
                                String msg = content[0] + "对"
                                        + cb.getClientName() + "说" + content[2];
                                sendPrivate(msg, cb);
                            }
                        }
                    }
                    //当客户端直接关闭窗台时,从JList中直接移除用户信息
                } catch (IOException e) {
                    if (flag) {
                        DefaultListModel dlm = (DefaultListModel) jList_user
                                .getModel();
                        //判断用户是否被管理员踢出来,若果不是就欢送
                        if (dlm.contains(cb)) {
                            dlm.removeElement(cb);
                            String goodbye = "欢送【" + cb.getClientName()
                                    + "】离开聊天室";
                            sendAll(goodbye);
                            sendList();
                        }
                    }

                }
            }
        }

        //点击发送按钮
        private void jButton_sendActionPerformed(java.awt.event.ActionEvent evt) {

            String imp = jTextField_import.getText().trim();
            jTextField_import.setText("");
            if (imp.equals("")) {
                JOptionPane.showMessageDialog(null, "发送的信息不能为空");
            } else {
                //获得发送信息的类型
                int index = jComboBox1.getSelectedIndex();
                //索引0代表群聊
                if (index == 0) {
                    String msg = "管理员对说有人说:" + imp;
                    sendAll(msg);
                } else {
                    Object obj = jList_user.getValueIsAdjusting();
                    if (obj == null) {
                        JOptionPane.showMessageDialog(null, "私聊必须选择一个用户");
                    } else {
                        ClientBean cb = (ClientBean) obj;
                        String msg = "管理员对" + cb.getClientName() + "说:" + imp;
                        sendPrivate(msg, cb);
                    }
                }
            }

        }

    }

    //发送群聊信息
    private void sendAll(String msg) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
        String getTime = sdf.format(new Date());
        jTextArea1.append(getTime+"\n"+msg + "\n");
        try {
            bw.write(msg+"\n");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Enumeration em = ((DefaultListModel) jList_user.getModel()).elements();
        if (em.hasMoreElements()) {
            ClientBean cb = (ClientBean) em.nextElement();
            cb.getPw().println(msg);
        }
    }

    //发送私有的信息
    public void sendPrivate(String text, ClientBean cb) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
        String getTime = sdf.format(new Date());
        jTextArea1.append(getTime+"\n"+text + "\n");
        try {
            bw.write(text);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        cb.getPw().println(text);
    }

    private void sendList() {
        DefaultListModel dlm = (DefaultListModel) jList_user.getModel();
        Enumeration em = dlm.elements();
        if (em.hasMoreElements()) {
            ClientBean cb = (ClientBean) em.nextElement();
            cb.getPw().println("list:" + dlm.toString());
        }
    }

    //判断用户列表中是否含有相同的昵称
    public boolean existsClientName(String clientnName) {
        boolean flag = false;
        Enumeration emu = ((DefaultListModel) jList_user.getModel()).elements();
        while (emu.hasMoreElements()) {
            ClientBean cb = (ClientBean) emu.nextElement();
            if (cb.getClientName().equals(clientnName)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    // 关闭服务器
    private void stopServer() {
        try {
            flag = false;
            jLabel_sate.setText("关   闭");
            jButton_initiator.setText("启动服务器");
            socket.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "关闭服务器失败!");
        }

    }

//  public static void main(String args[]) {
//      java.awt.EventQueue.invokeLater(new Runnable() {
//          public void run() {
//              new ServerFrame().setVisible(true);
//          }
//      });
//  }

    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton_initiator;
    private javax.swing.JButton jButton_kick;
    private javax.swing.JButton jButton_send;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel_sate;
    private javax.swing.JList jList_user;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField_import;
    // End of variables declaration//GEN-END:variables
    private ServerSocket socket;
    private BufferedWriter bw;
    private String fileName;
    private String dir;
    private File fileDir;

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==jButton4){
            try {
                int chose = JOptionPane.showConfirmDialog(null, "您需要保存聊天记录吗?",
                        "提  示", JOptionPane.OK_CANCEL_OPTION);
                if (chose == JOptionPane.OK_OPTION) {
                    bw.flush();//写入的过程
                    JOptionPane.showMessageDialog(null, "聊天记录保存成功!");
                } else {

                }
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode()==KeyEvent.VK_ESCAPE){

            int i = JOptionPane.showConfirmDialog(null, "是否退出?",
                    "提  示", JOptionPane.YES_NO_OPTION);
            if(i==0){
                this.dispose();
                new MainFrame(p).setVisible(true);
            }
        }

    }

    @Override
    public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub

    }

}

dao
ClassDao.java

package cn.com.zh.dao;

import java.util.List;

import cn.com.zh.entity.Class;
import cn.com.zh.entity.Course;
import cn.com.zh.entity.Sign;

public interface ClassDao {

    //查询班级的方法
    public List<Class> allClass(Class c);

    //增加班级的方法
    public boolean addClass(Class c);

    //修改班级的方法
    public boolean updateClass(Class c);

    //删除班级
    public boolean deleteClass(int gid);

    //动态加载班级名称下拉框
    public List<Class> lodeClassName();

    //更据学生编号查询该学生所在的班级
    public List<Class> findClassinfoBySid(int sid);

    //更据专业编号查询班级信息
    public List<Class> findClassInfoByMid(int mid);

}

MessageDao.java

package cn.com.zh.dao;

import java.util.List;

import cn.com.zh.entity.Board;
import cn.com.zh.entity.Message;

public interface MessageDao {

    public List<Message> findMessage(Message m);

    public boolean deleteMessage(int mid);

    public boolean addMessage(Message m);

    // 分页查询留言信息
    public List<Message> findAllMessageLimt();

}

AddCouDialog.java

/*
 * AddCouDialog.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.zh.dialog;

import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import cn.com.zh.dao.CourseDao;
import cn.com.zh.dao.CourseDaoImpl;
import cn.com.zh.dao.MajorDao;
import cn.com.zh.dao.MajorDaoImpl;
import cn.com.zh.entity.Course;
import cn.com.zh.entity.Major;

/**
 *
 * @author  __USER__
 */
public class AddCouDialog extends javax.swing.JDialog {

    /** Creates new form AddCouDialog */
    public AddCouDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        ImageIcon image = new ImageIcon("img/courseTit.png");
        setIconImage(image.getImage());
        lodeMajorName();
    }

    //动态加载专业下拉框
    public void lodeMajorName() {
        MajorDao majorDao = new MajorDaoImpl();
        List<Major> lodeMajorName = majorDao.lodeMajorName();
        jComboBox1.addItem("----请选择----");
        for (int i = 0; i < lodeMajorName.size(); i++) {
            Major major = lodeMajorName.get(i);
            jComboBox1.addItem(major);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel4 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("\u6dfb\u52a0\u8bfe\u7a0b\u4fe1\u606f");

jLabel1.setFont(new java.awt.Font("楷体", 1, 24));
jLabel1.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\course.png")); // NOI18N
jLabel1.setText("\u589e\u52a0\u8bfe\u7a0b\u4fe1\u606f");

jButton1.setFont(new java.awt.Font("楷体", 1, 18));
jButton1.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\StuSure.png")); // NOI18N
jButton1.setText("\u786e\u5b9a");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setFont(new java.awt.Font("楷体", 1, 18));
jButton2.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\StuReset.png")); // NOI18N
jButton2.setText("\u91cd\u7f6e");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jLabel2.setFont(new java.awt.Font("楷体", 1, 18));
jLabel2.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\Couname.png")); // NOI18N
jLabel2.setText("\u8bfe\u7a0b\u540d\u79f0:");

jTextField1.setFont(new java.awt.Font("楷体", 1, 18));

jLabel3.setFont(new java.awt.Font("楷体", 1, 18));
jLabel3.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\CouType.png")); // NOI18N
jLabel3.setText("\u8bfe\u7a0b\u63cf\u8ff0:");

jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("楷体", 1, 18));
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jLabel4.setFont(new java.awt.Font("楷体", 1, 18));
jLabel4.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\Classcname.png")); // NOI18N
jLabel4.setText("\u4e13\u4e1a\u540d\u79f0:");

jComboBox1.setFont(new java.awt.Font("楷体", 1, 18));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(73, 73, 73)
.addComponent(jButton1)
.addGap(64, 64, 64)
.addComponent(jButton2)
.addContainerGap(80, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jComboBox1, 0, 233, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)))))
.addGap(24, 24, 24))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(67, 67, 67)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(50, 50, 50))
);

pack();
}// </editor-fold>

    //GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        jTextField1.setText("");
        jTextField1.requestFocus();
        jTextArea1.setText("");
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String cName = jTextField1.getText();
        String ctype = jTextArea1.getText();
        int index = jComboBox1.getSelectedIndex();

        if (cName.equals("")) {
            JOptionPane.showMessageDialog(null, "课程名称不能为空,请重新输入!", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
            jTextField1.requestFocus();
            return;
        }
        if (ctype.equals("")) {
            JOptionPane.showMessageDialog(null, "课程描述不能为空,请重新输入!", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
            jTextField1.requestFocus();
            return;
        }

        CourseDao courseDao = new CourseDaoImpl();
        Course c = new Course(cName, ctype);

        int i = JOptionPane.showConfirmDialog(null, "确认添加该课程信息!", "温馨提示",
                JOptionPane.YES_NO_OPTION);
        if (i == 0) {
            Integer addCourse = courseDao.addCourse(c);
            if (index > 0) {
                if (addCourse > 0) {
                    Major major = (Major) jComboBox1.getSelectedItem();
                    boolean addMajorCourse = courseDao.addMajorCourse(
                            addCourse, major.getMid());
                    if (addMajorCourse) {
                        JOptionPane.showMessageDialog(null, "添加课程以及所属专业信息成功!",
                                "温馨提示", JOptionPane.INFORMATION_MESSAGE);
                        this.setVisible(false);
                    } else {
                        JOptionPane.showMessageDialog(null, "添加课程以及所属专业信息失败!",
                                "温馨提示", JOptionPane.ERROR_MESSAGE);
                    }
                }
            } else {
                if (addCourse > 0) {
                    JOptionPane.showMessageDialog(null, "添加课程信息成功!", "温馨提示",
                            JOptionPane.INFORMATION_MESSAGE);
                    this.setVisible(false);
                } else {
                    JOptionPane.showMessageDialog(null, "添加课程信息失败!", "温馨提示",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AddCouDialog dialog = new AddCouDialog(
                        new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}

entity实体类
Class.java

package cn.com.zh.entity;

public class Class {
    private int gid;
    private String gname;
    private String gtype;
    private int cid;
    private String cname;
    private int mid;
    private String mName;
    private int sid;//学生id
    private String sname;//学生姓名

    public String getCname() {
        return cname;
    }
    public void setCname(String cname) {
        this.cname = cname;
    }
    public int getCid() {
        return cid;
    }
    public void setCid(int cid) {
        this.cid = cid;
    }
    public int getGid() {
        return gid;
    }
    public void setGid(int gid) {
        this.gid = gid;
    }
    public String getGname() {
        return gname;
    }
    public void setGname(String gname) {
        this.gname = gname;
    }
    public String getGtype() {
        return gtype;
    }
    public void setGtype(String gtype) {
        this.gtype = gtype;
    }

    public int getMid() {
        return mid;
    }
    public void setMid(int mid) {
        this.mid = mid;
    }
    public String getmName() {
        return mName;
    }
    public void setmName(String mName) {
        this.mName = mName;
    }
    @Override
    public String toString() {
        return gname;
    }
    public int getSid() {
        return sid;
    }
    public void setSid(int sid) {
        this.sid = sid;
    }
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }
    public Class() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Class(String gname, int mid) {
        super();
        this.gname = gname;
        this.mid = mid;
    }

    public Class(String gname, String gtype, int mid) {
        super();
        this.gname = gname;
        this.gtype = gtype;
        this.mid = mid;
    }

    public Class(int gid, String gname, String gtype, int mid) {
        super();
        this.gid = gid;
        this.gname = gname;
        this.gtype = gtype;
        this.mid = mid;
    }
    public Class(String gname, String cname) {
        super();
        this.gname = gname;
        this.cname = cname;
    }

}

Grade.java

package cn.com.zh.entity;

public class Grade {
    private int sid;     //学生ID
    private String sName;//学生姓名
    private String cName;//课程名称
    private String gName;//班级名称
    private float score;//专业成绩

    public int getSid() {
        return sid;
    }
    public void setSid(int sid) {
        this.sid = sid;
    }
    public String getsName() {
        return sName;
    }
    public void setsName(String sName) {
        this.sName = sName;
    }
    public String getcName() {
        return cName;
    }
    public void setcName(String cName) {
        this.cName = cName;
    }
    public String getgName() {
        return gName;
    }
    public void setgName(String gName) {
        this.gName = gName;
    }
    public float getScore() {
        return score;
    }
    public void setScore(float score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Grade [sid=" + sid + ", sName=" + sName + ", cName=" + cName
                + ", gName=" + gName + ", score=" + score + "]";
    }

    public Grade() {
        super();
        // TODO Auto-generated constructor stub
    }

}

小游戏
GamePanel.java

package cn.com.zh.snake;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;

import cn.com.zh.dao.UserDao;
import cn.com.zh.dao.UserDaoImp;
import cn.com.zh.entity.User;

/**
 * 
 * @author Administrator
 *蛇的游戏面板高度:650,高度:750
 */

public class GamePanel extends JPanel implements KeyListener,ActionListener {

    ImageIcon title=new ImageIcon("snake/title.jpg");
    ImageIcon body=new ImageIcon("snake/body.png");
    ImageIcon down=new ImageIcon("snake/down.png");
    ImageIcon food=new ImageIcon("snake/food.png");
    ImageIcon right=new ImageIcon("snake/right.png");
    ImageIcon left=new ImageIcon("snake/left.png");
    ImageIcon up=new ImageIcon("snake/up.png");
    ImageIcon foods=new ImageIcon("snake/foods.jpg");

    int snakeX[]=new int[750];
    int snakeY[]=new int[750];

    int len=3;//设置蛇的总长度

    int score=0;//定义蛇的分数

    int counts=0;//定义食物出现的次数
    //设置蛇的方向
    String dirction="R";

    //设置是否开始的游戏变量
    boolean isStart=false;
    //判断游戏是否结束
    boolean isOver=false;

    //定义一个定时器让它移动  第一个参数表示时间间隔
    Timer timer=new Timer(100, this);

    //定义一个随机函数让它随机产生食物
    Random random=new Random();

    int foodX;
    int foodY;

    //生成食物的方法
    public void creadFood(){
        counts++;
        foodX=random.nextInt(34)*25+25;
        foodY=random.nextInt(24)*25+75;
    }

    public void eatFood(){
        len++;
        if(counts%5==0){
            score+=random.nextInt(30)+20;
        }else{
            score+=10;
        }
    }

    public void initSanke(){
        isStart=false;
        isOver=false;
        score=0;
        len=3;
        dirction="R";
        counts=0;
        snakeX[0]=75;
        snakeY[0]=75;
        snakeX[1]=50;
        snakeY[1]=75;
        snakeX[2]=25;
        snakeY[2]=75;
    }

    @Override
    public void paint(Graphics g) {

        g.fillRect(25, 75, 850, 600);
        title.paintIcon(this, g, 25, 11);

        if(dirction.equals("R")){
            right.paintIcon(this, g, snakeX[0], snakeY[0]);
        }else if(dirction.equals("L")){
            left.paintIcon(this, g, snakeX[0], snakeY[0]);
        }else if(dirction.equals("U")){
            up.paintIcon(this, g, snakeX[0], snakeY[0]);
        }else if(dirction.equals("D")){
            down.paintIcon(this, g, snakeX[0], snakeY[0]);
        }

        for (int i = 1; i <len; i++) {
            body.paintIcon(this, g, snakeX[i], snakeY[i]);
        }

        //判断游戏是否点击空格开始
        if(!isStart){
            g.setColor(Color.blue);
            g.setFont(new Font("楷体", Font.BOLD,20));
            g.drawString("开始/暂停", 425, 325);            
        }

        //绘制食物
        if(counts%5==0){
            foods.paintIcon(this, g, foodX, foodY);
        }else if(score==0){
            food.paintIcon(this, g, foodX, foodY);
        }else{
            food.paintIcon(this, g, foodX, foodY);
        }

        //绘制分数和蛇的长度
        g.setColor(Color.red);
        g.setFont(new Font("微软雅黑", Font.BOLD, 20));
        g.drawString("长度:"+len,650,30);
        g.setColor(Color.red);
        g.setFont(new Font("微软雅黑", Font.BOLD, 20));
        g.drawString("分数:"+score, 650,60);

        //判断游戏是否结束
        if(isOver){
             int i = JOptionPane.showConfirmDialog(null, "你死了,是否重新开始!!!",
             "温馨提示", JOptionPane.YES_NO_OPTION);
             if(i==0){
                 frame.dispose();
                 new SnakeFrame(u).setVisible(true);
             }else{
                 UserDao userDao=new UserDaoImp();
                 u.setScore(score);
                 boolean updatePlayScore = userDao.updatePlayScore(u);
                 if(updatePlayScore){
                     JOptionPane.showMessageDialog(null, "添加分数成功,返回贪吃蛇主界面!!", "温馨提示",JOptionPane.INFORMATION_MESSAGE);
                     frame.dispose();
                     new cn.com.zh.ui.SnakeFrame(u).setVisible(true);
                 }else{
                     JOptionPane.showMessageDialog(null, "保存失败!", "温馨提示",
                                JOptionPane.ERROR_MESSAGE);
                     frame.dispose();
                     new cn.com.zh.ui.SnakeFrame(u).setVisible(true);
                 }
             }
        }

    }

    JFrame frame;
    User u;
    public GamePanel(JFrame frame,User u){
        this.frame=frame;
        this.u=u;
        this.setFocusable(true);
        this.addKeyListener(this);
        initSanke();
        creadFood();
        timer.start();
    }

    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode()==KeyEvent.VK_SPACE){
            if(isOver){
                initSanke();
            }else{
            isStart=!isStart;//通过按下空格监听是否开始游戏
            }
            repaint();
        }else if(e.getKeyCode()==KeyEvent.VK_RIGHT && !dirction.equals("L")){//通过键盘控制蛇的移动
            dirction="R";
        }else if(e.getKeyCode()==KeyEvent.VK_LEFT && !dirction.equals("R")){
            dirction="L";
        }else if(e.getKeyCode()==KeyEvent.VK_UP && !dirction.equals("D")){
            dirction="U";
        }else if(e.getKeyCode()==KeyEvent.VK_DOWN && !dirction.equals("U")){
            dirction="D";
        }

        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
            isStart=false;
            int i = JOptionPane.showConfirmDialog(null, "你确定要退出这么经典的游戏吗?",
                    "温馨提示", JOptionPane.YES_NO_OPTION);
            if (i == 0) {
                UserDao userDao = new UserDaoImp();
                u.setScore(score);
                boolean updatePlayScore = userDao.updatePlayScore(u);
                if (updatePlayScore) {
                    JOptionPane.showMessageDialog(null, "保存游戏分数成功,返回贪吃蛇主界面!!",
                            "温馨提示", JOptionPane.INFORMATION_MESSAGE);
                    frame.setVisible(false);
                    new cn.com.zh.ui.SnakeFrame(u).setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "保存游戏分数成功!", "温馨提示",
                            JOptionPane.ERROR_MESSAGE);
                    frame.setVisible(false);
                    new cn.com.zh.ui.SnakeFrame(u).setVisible(true);
                }
            } else {
                isStart=true;
            }
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(isStart && !isOver){
            //启动定时器
            timer.start();
            //蛇身的移动
            for (int i = len; i >0; i--) {
                snakeX[i]=snakeX[i-1];
                snakeY[i]=snakeY[i-1];
            }
            //蛇头的移动
            if(dirction.equals("R")){
                if(snakeX[0]>=850){
                    snakeX[0]=25;
                }else{
                    snakeX[0]=snakeX[0]+25;
                }
            }else if(dirction.equals("L")){
                if(snakeX[0]<=25){
                    snakeX[0]=850;
                }else{
                    snakeX[0]=snakeX[0]-25;
                }
            }else if(dirction.equals("U")){
                if(snakeY[0]<=75){
                    snakeY[0]=650;
                }else{
                    snakeY[0]=snakeY[0]-25;
                }
            }else if(dirction.equals("D")){
                if(snakeY[0]>=650){
                    snakeY[0]=75;
                }else{
                    snakeY[0]=snakeY[0]+25;
                }
            }

            //蛇吃到食物
            if(snakeX[0]==foodX && snakeY[0]==foodY){
                eatFood();
                creadFood();

                //判断食物是否在蛇的身上产生
                for (int i = 0; i < len; i++) {
                    if(foodX==snakeX[i] && foodY==snakeY[i]){
                        foodX=random.nextInt(34)*25+25;
                        foodY=random.nextInt(24)*25+75;
                        break;
                    }
                }
            }
            for (int i=1;i< len; i++) {
                if(snakeX[0]==snakeX[i] && snakeY[0]==snakeY[i]){
                    isOver=true;
                }   
            }
            repaint();
        }

    }

}

SnakeFrame.java

package cn.com.zh.snake;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.com.zh.entity.User;
import cn.com.zh.ui.MainFrame;

public class SnakeFrame extends JFrame {

    /**
     * @param arg
     *绘制贪吃蛇的游戏主窗口 
     */

    public SnakeFrame(final User u){
        setTitle("贪吃蛇最强版");
        setSize(925, 750);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        GamePanel gamePanel=new GamePanel(this,u);
        this.add(gamePanel);

        setVisible(true);

        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int i = JOptionPane.showConfirmDialog(null, "确定要退出,返回主界面吗?",
                        "温馨提示", JOptionPane.YES_NO_OPTION);
                if (i == 0) {
                    setVisible(false);
                    new cn.com.zh.ui.SnakeFrame(u).setVisible(true);
                }
            }
        });

    }

//  public static void main(String[] args) {
//      new SnakeFrame();
//  }

}

音乐系统
MusicThread.java

package cn.com.zh.thread;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

/**
 * 
 * @author Administrator
 *实现播放音乐的线程
 */

public class MusicThread implements Runnable {

    private Player player;//定义播放音乐变量

    //创建播放音乐的构造方法
    public MusicThread(String path){
        try {
            FileInputStream in=new FileInputStream(path);
            player=new Player(in);
            Thread th=new Thread(this);
            th.start();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }

    //关闭资源关闭音乐
    public void closes(){
        player.close();
    }

    @Override
    public void run() {
        try {
            player.play();
        } catch (JavaLayerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

班级
ClassInterna.java

/*
 * ClassInterna.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.zh.viewInterna;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import cn.com.zh.dao.ClassDao;
import cn.com.zh.dao.ClassDaoImpl;
import cn.com.zh.dao.CourseDao;
import cn.com.zh.dao.CourseDaoImpl;
import cn.com.zh.dao.MajorDao;
import cn.com.zh.dao.MajorDaoImpl;
import cn.com.zh.dao.RoleDao;
import cn.com.zh.dao.RoleDaoImpl;
import cn.com.zh.dao.StudentDao;
import cn.com.zh.dao.StudentDaoImpl;
import cn.com.zh.dialog.AddClassDialog;
import cn.com.zh.dialog.AllClassStuDialog;
import cn.com.zh.dialog.UpdateClassDialog;
import cn.com.zh.entity.Class;
import cn.com.zh.entity.Course;
import cn.com.zh.entity.Major;
import cn.com.zh.entity.Role;
import cn.com.zh.entity.Student;
import cn.com.zh.util.ViewUtils;

/**
 *
 * @author  __USER__
 */
public class ClassInterna extends javax.swing.JInternalFrame {

    /** Creates new form ClassInterna */
    ViewUtils utils = new ViewUtils();
    JFrame frame;

    public ClassInterna(JFrame frame) {
        this.frame = frame;
        initComponents();
        ImageIcon icon = new ImageIcon("img/classTit.png");
        setFrameIcon(icon);
        allClass(null);
        //      jTable1.addMouseListener(new MouseAdapter() {
        //          @Override
        //          public void mouseClicked(MouseEvent e) {
        //              if (e.getClickCount() == 2) {
        //                  JTable source = (JTable) e.getSource();
        //                  int row = source.rowAtPoint(e.getPoint());
        //                  int column = source.columnAtPoint(e.getPoint());
        //                  String valueAt = (String) jTable1.getValueAt(row, 2);
        //                  JOptionPane.showMessageDialog(null, valueAt);
        //              }
        //          }
        //      });
        lodeMajorName();
        tableMouse();
    }

    //动态加载专业的方法
    public void lodeMajorName() {
        MajorDao majorDao = new MajorDaoImpl();
        List<Major> lodeMajorName = majorDao.lodeMajorName();
        jComboBox1.addItem("----请选择----");
        for (int i = 0; i < lodeMajorName.size(); i++) {
            Major major = lodeMajorName.get(i);
            jComboBox1.addItem(major);
        }
    }

    //表格的事件监听
    public void tableMouse() {
        jTable1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    int column = jTable1.getSelectedColumn();
                    int row = jTable1.getSelectedRow();
                    if (column == 4) {
                        Class class1 = list.get(row);
                        new AllClassStuDialog(frame, true, class1);
                    }
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jComboBox1 = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();

setClosable(true);
setIconifiable(true);
setMaximizable(true);
setTitle("\u73ed\u7ea7\u4fe1\u606f");

jLabel1.setFont(new java.awt.Font("楷体", 1, 18));
jLabel1.setText("\u73ed\u7ea7\u540d\u79f0:");

jTextField1.setFont(new java.awt.Font("楷体", 1, 18));

jButton2.setFont(new java.awt.Font("楷体", 1, 18));
jButton2.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\addStuBut.png")); // NOI18N
jButton2.setText("\u589e  \u52a0");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setFont(new java.awt.Font("楷体", 1, 18));
jButton3.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\StuSure.png")); // NOI18N
jButton3.setText("\u4fee  \u6539");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setFont(new java.awt.Font("楷体", 1, 18));
jButton4.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\delete.png")); // NOI18N
jButton4.setText("\u5220  \u9664");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton1.setFont(new java.awt.Font("楷体", 1, 18));
jButton1.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\query.png")); // NOI18N
jButton1.setText("\u67e5  \u8be2");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTable1.setFont(new java.awt.Font("楷体", 1, 18));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {

    },
    new String [] {
        "班级编号", "班级名称", "班级描述", "专业名称", "操       作"
    }
) {
    boolean[] canEdit = new boolean [] {
        false, false, false, false, false
    };

    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
    }
});
jTable1.setOpaque(false);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);

jComboBox1.setFont(new java.awt.Font("楷体", 1, 14));

jLabel2.setFont(new java.awt.Font("楷体", 1, 18));
jLabel2.setText("\u4e13\u4e1a\u540d\u79f0:");

jLabel3.setFont(new java.awt.Font("楷体", 1, 14));
jLabel3.setForeground(new java.awt.Color(255, 0, 0));
jLabel3.setText("\u8bf7\u7528\u9f20\u6807\u53cc\u51fb\u67e5\u770b\u8be6\u7ec6\uff0c\u67e5\u770b\u6bcf\u4e2a\u73ed\u7ea7\u76f8\u5e94\u7684\u4eba\u6570");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addGap(62, 62, 62))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(247, Short.MAX_VALUE)
.addComponent(jLabel3)
.addGap(242, 242, 242))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jButton1)
.addComponent(jLabel2)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton4)
.addComponent(jButton3))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addContainerGap())
);

pack();
}// </editor-fold>

    //GEN-END:initComponents

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {

    }

    //查询
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String gname = jTextField1.getText();
        int index = jComboBox1.getSelectedIndex();
        int majorID = 0;
        if (index > 0) {
            Major major = (Major) jComboBox1.getSelectedItem();
            majorID = major.getMid();
        } else {
            majorID = 0;
        }
        Class c = new Class(gname, majorID);
        allClass(c);

    }

    //删除班级信息按钮
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        deleteClass();
    }

    //修改班级信息按钮
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        updateClass();
    }

    //添加班级信息按钮
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        new AddClassDialog(frame, true).setVisible(true);
        allClass(null);
    }

    //查询所有班级的方法
    public void allClass(Class c) {
        ClassDao classDao = new ClassDaoImpl();
        list = classDao.allClass(c);

        if (list.size() <= 0) {
            JOptionPane.showMessageDialog(null, "暂时没有该班级信息");
        } else {
            DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
            model.setRowCount(0);
            for (int i = 0; i < list.size(); i++) {
                classInfo = list.get(i);
                Vector rowData = new Vector();
                rowData.add(classInfo.getGid());
                rowData.add(classInfo.getGname());
                rowData.add(classInfo.getGtype());
                rowData.add(classInfo.getmName());
                rowData.add("查看详细");
                model.addRow(rowData);
            }
            utils.fitTableColumns(jTable1);
        }
    }

    //修改班级信息
    public void updateClass() {
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "请选择您需要修改班级的信息", "温馨提示",
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            classInfo = list.get(selectedRow);
            new UpdateClassDialog(frame, true).setVisible(true);
            allClass(null);
        }
    }

    //删除班级信息
    public void deleteClass() {
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(null, "请选择您需要删除班级的信息", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            classInfo = list.get(selectedRow);
            StudentDao dao=new StudentDaoImpl();
            List<Student> studentByCid = dao.findStudentByCid(classInfo.getGid());
            if(studentByCid.size()<=0){
                ClassDao classDao = new ClassDaoImpl();
                int i = JOptionPane.showConfirmDialog(null, "是否确认删除班级信息!", "温馨提示",
                        JOptionPane.YES_NO_OPTION);
                if (i == 0) {
                    boolean deleteClass = classDao.deleteClass(classInfo.getGid());
                    if (deleteClass) {
                        JOptionPane.showMessageDialog(null, "删除成功!", "温馨提示",
                                JOptionPane.INFORMATION_MESSAGE);
                        allClass(null);
                    } else {
                        JOptionPane.showMessageDialog(null, "删除失败!", "温馨提示",
                                JOptionPane.ERROR_MESSAGE);
                    }
                }
            }else{
                JOptionPane.showMessageDialog(null, "该班级还存在学生不能删除该班级信息!", "温馨提示",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    private List<Class> list;
    public static Class classInfo;

}

成绩
GradeInterna.java

/*
 * GradeInterna.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.zh.viewInterna;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import cn.com.zh.dao.ClassDao;
import cn.com.zh.dao.ClassDaoImpl;
import cn.com.zh.dao.MajorDao;
import cn.com.zh.dao.MajorDaoImpl;
import cn.com.zh.dao.StudentDao;
import cn.com.zh.dao.StudentDaoImpl;
import cn.com.zh.dialog.AddGradeDialog;
import cn.com.zh.dialog.GradeDialog;
import cn.com.zh.entity.Class;
import cn.com.zh.entity.Major;
import cn.com.zh.entity.Student;
import cn.com.zh.util.ViewUtils;

/**
 *
 * @author  __USER__
 */
public class GradeInterna extends javax.swing.JInternalFrame {

    /** Creates new form GradeInterna */
    JFrame frame;
    ViewUtils utils = new ViewUtils();

    public GradeInterna(JFrame frame) {
        this.frame = frame;
        initComponents();
        ImageIcon image = new ImageIcon("img/couTitle.png");
        setFrameIcon(image);
        allStu(null);
        lodeClassName();
        lodeMajorName();
        tableMouse();
    }

    //动态加载专业名称
    public void lodeMajorName() {
        MajorDao majorDao = new MajorDaoImpl();
        List<Major> lodeMajorName = majorDao.lodeMajorName();
        jComboBox2.addItem("----请选择----");
        for (int i = 0; i < lodeMajorName.size(); i++) {
            Major major = lodeMajorName.get(i);
            jComboBox2.addItem(major);
        }
    }

    //动态加载班级名称
    public void lodeClassName() {
        ClassDao classDao = new ClassDaoImpl();
        List<Class> lodeClassName = classDao.lodeClassName();
        jComboBox1.addItem("----请选择----");
        for (int i = 0; i < lodeClassName.size(); i++) {
            Class class1 = lodeClassName.get(i);
            jComboBox1.addItem(class1);
        }
    }

    //为表格添加鼠标点击事件
    public void tableMouse() {

        jTable1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    int column = jTable1.getSelectedColumn();
                    int row = jTable1.getSelectedRow();
                    if (column == 5) {
                        Student student2 = list.get(row);
                        new GradeDialog(frame, true, student2);
                    }
                    if (column == 6) {
                        Student deleteStu = list.get(row);
                        StudentDao studentDao = new StudentDaoImpl();
                        int i = JOptionPane.showConfirmDialog(null,
                                "是否确认删除该学生成绩!", "温馨提示",
                                JOptionPane.YES_NO_OPTION);
                        if (i == 0) {
                            boolean deleteScoreStu = studentDao
                                    .deleteScoreStu(deleteStu.getSid());
                            if (deleteScoreStu) {
                                JOptionPane
                                        .showMessageDialog(null, "删除成功!",
                                                "温馨提示",
                                                JOptionPane.INFORMATION_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "该学生成绩已被删除!",
                                    "温馨提示", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                    if (column == 7) {
                        Student student2 = list.get(row);
                        new AddGradeDialog(frame, true, student2);
                    }
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();

setClosable(true);
setIconifiable(true);
setMaximizable(true);
setTitle("\u6210\u7ee9\u7ba1\u7406");

jTable1.setFont(new java.awt.Font("楷体", 1, 18));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {

    },
    new String [] {
        "学生序号", "学       号", "姓       名", "专    业&编    号", "班       级", "成绩入口", "操        作", "成绩录入"
    }
) {
    boolean[] canEdit = new boolean [] {
        false, false, false, false, false, false, false, false
    };

    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
    }
});
jTable1.setOpaque(false);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);

jLabel1.setFont(new java.awt.Font("楷体", 1, 18));
jLabel1.setText("\u5b66\u751f\u540d\u79f0:");

jTextField1.setFont(new java.awt.Font("楷体", 1, 18));

jLabel2.setFont(new java.awt.Font("楷体", 1, 18));
jLabel2.setText("\u6240\u5c5e\u73ed\u7ea7:");

jComboBox1.setFont(new java.awt.Font("楷体", 1, 14));

jButton1.setFont(new java.awt.Font("楷体", 1, 18));
jButton1.setIcon(new javax.swing.ImageIcon("D:\\software\\MyEclipse10Packe\\EndDom\\img\\query.png")); // NOI18N
jButton1.setText("\u67e5  \u8be2");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel3.setFont(new java.awt.Font("楷体", 1, 18));
jLabel3.setText("\u6240\u5c5e\u4e13\u4e1a:");

jComboBox2.setFont(new java.awt.Font("楷体", 1, 14));

jLabel4.setFont(new java.awt.Font("楷体", 1, 18));
jLabel4.setForeground(new java.awt.Color(255, 0, 51));
jLabel4.setText("\u8bf7\u53cc\u51fb\u9f20\u6807\u70b9\u51fb\u76f8\u5bf9\u5e94\u7684\u529f\u80fd\u5165\u53e3\uff0c\u5b9e\u73b0\u76f8\u5bf9\u5e94\u7684\u529f\u80fd");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap(43, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(275, 275, 275))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 980, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(29, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(56, 56, 56)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(33, 33, 33)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 436, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel4)
.addGap(32, 32, 32))
);

pack();
}// </editor-fold>

    //GEN-END:initComponents
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String stuName = jTextField1.getText();
        int indexClass = jComboBox1.getSelectedIndex();
        int indexMajor = jComboBox2.getSelectedIndex();
        int ClassID = 0;
        int MajorID = 0;
        if (indexClass > 0) {
            Class className = (Class) jComboBox1.getSelectedItem();
            ClassID = className.getGid();
        } else {
            ClassID = 0;
        }

        if (indexMajor > 0) {
            Major majorName = (Major) jComboBox2.getSelectedItem();
            MajorID = majorName.getMid();
        } else {
            MajorID = 0;
        }

        Student s = new Student(stuName, ClassID, MajorID);
        allStu(s);
    }

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {

    }

    //查询学生的方法
    public void allStu(Student s) {
        StudentDao studentDao = new StudentDaoImpl();
        list = studentDao.findAllSorce(s);

        if (list.size() <= 0) {
            JOptionPane.showMessageDialog(null, "暂时没有该学生信息");
        } else {
            DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
            model.setRowCount(0);
            for (int i = 0; i < list.size(); i++) {
                student = list.get(i);
                Vector rowData = new Vector<>();
                rowData.add(i + 1);
                rowData.add(student.getSid());
                rowData.add(student.getSname());
                rowData.add(student.getMname() + "&" + student.getMid());
                rowData.add(student.getCname());
                rowData.add("查看成绩");
                rowData.add("删除成绩");
                rowData.add("录入成绩");
                model.addRow(rowData);
            }
            utils.fitTableColumns(jTable1);
        }

    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    private List<Student> list;
    public static Student student;

}

专业
MajorInterna.java

/*
 * MajorInterna.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.zh.viewInterna;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import cn.com.zh.dao.ClassDao;
import cn.com.zh.dao.ClassDaoImpl;
import cn.com.zh.dao.MajorDao;
import cn.com.zh.dao.MajorDaoImpl;
import cn.com.zh.dialog.AddMajorDialog;
import cn.com.zh.dialog.UpdateMajorDialog;
import cn.com.zh.entity.Class;
import cn.com.zh.entity.Course;
import cn.com.zh.entity.Major;
import cn.com.zh.util.ViewUtils;

/**
 *
 * @author  __USER__
 */
public class MajorInterna extends javax.swing.JInternalFrame {

    /** Creates new form MajorInterna */
    JFrame frame;
    ViewUtils utils = new ViewUtils();

    public MajorInterna(JFrame frame) {
        this.frame = frame;
        initComponents();
        ImageIcon image = new ImageIcon("img/couTitle.png");
        setFrameIcon(image);
        allMajor(null);

        jTable1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    //获取表格中的每行和第一列
                    JTable source = (JTable) e.getSource();
                    //获取表格中的每行
                    int row = source.rowAtPoint(e.getPoint());
                    //获取表格中每行第1列的值
                    int mid = (int) jTable1.getValueAt(row, 0);
                    MajorDao majorDao = new MajorDaoImpl();
                    List<Course> findCourseByMid = majorDao
                            .findCourseByMid(mid);
                    if (findCourseByMid.size() <= 0) {
                        JOptionPane.showMessageDialog(null, "改专业下暂时没有课程信息!!!",
                                "温馨提示", JOptionPane.ERROR_MESSAGE);
                    } else {
                        //创建集合保存课程名字
                        List<String> courseName_list = new ArrayList<String>();
                        for (int i = 0; i < findCourseByMid.size(); i++) {
                            //获取集合中的课程信息
                            Course course = findCourseByMid.get(i);
                            //把课程名字添加到集合中
                            courseName_list.add(course.getCname());
                        }
                        //定义字符串保存课程名字,初始化为null
                        String mname = "";
                        //遍历保存课程的集合
                        for (int i = 0; i < courseName_list.size(); i++) {
                            //拼接课程名字
                            mname += courseName_list.get(i) + "\n";
                        }
                        JOptionPane.showMessageDialog(null, "该专业下所包含的课程:\n"
                                + mname + "\n", "温馨提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }

                }
            }
        });

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("\u4e13\u4e1a\u7ba1\u7406");

        jLabel1.setFont(new java.awt.Font("楷体", 1, 18));
        jLabel1.setText("\u4e13\u4e1a\u540d\u79f0:");

        jTextField1.setFont(new java.awt.Font("楷体", 1, 18));

        jButton2.setFont(new java.awt.Font("楷体", 1, 18));
        jButton2.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\addStuBut.png")); // NOI18N
        jButton2.setText("\u589e  \u52a0");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("楷体", 1, 18));
        jButton3.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\StuSure.png")); // NOI18N
        jButton3.setText("\u4fee  \u6539");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("楷体", 1, 18));
        jButton4.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\delete.png")); // NOI18N
        jButton4.setText("\u5220  \u9664");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("楷体", 1, 18));
        jButton1.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\query.png")); // NOI18N
        jButton1.setText("\u67e5  \u8be2");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTable1.setFont(new java.awt.Font("楷体", 1, 18));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] {

                }, new String[] { "专业编号", "专业名称", "专业描述" }) {
            boolean[] canEdit = new boolean[] { false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jTable1.setOpaque(false);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel2.setFont(new java.awt.Font("楷体", 1, 18));
        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("\u53cc\u51fb\u9f20\u6807\u70b9\u51fb\u67e5\u8be2\u6bcf\u4e2a\u4e13\u4e1a\u4e0b\u6240\u5bf9\u5e94\u7684\u8bfe\u7a0b");

        jLabel3.setFont(new java.awt.Font("楷体", 1, 18));
        jLabel3.setText("\u4e13\u4e1a\u63cf\u8ff0:");

        jTextField2.setFont(new java.awt.Font("楷体", 1, 18));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addComponent(
                                                                        jScrollPane1,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        833,
                                                                        Short.MAX_VALUE)
                                                                .addContainerGap())
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addGroup(
                                                                                        layout.createSequentialGroup()
                                                                                                .addGap(153,
                                                                                                        153,
                                                                                                        153)
                                                                                                .addComponent(
                                                                                                        jButton2))
                                                                                .addGroup(
                                                                                        layout.createSequentialGroup()
                                                                                                .addGap(39,
                                                                                                        39,
                                                                                                        39)
                                                                                                .addComponent(
                                                                                                        jLabel1)
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                .addComponent(
                                                                                                        jTextField1,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                        186,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                .addGroup(
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        layout.createSequentialGroup()
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                .addComponent(
                                                                                                        jButton3)
                                                                                                .addGap(109,
                                                                                                        109,
                                                                                                        109)
                                                                                                .addComponent(
                                                                                                        jButton4))
                                                                                .addGroup(
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        layout.createSequentialGroup()
                                                                                                .addGap(46,
                                                                                                        46,
                                                                                                        46)
                                                                                                .addComponent(
                                                                                                        jLabel3)
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                .addComponent(
                                                                                                        jTextField2,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                        186,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                .addGap(34,
                                                                                                        34,
                                                                                                        34)
                                                                                                .addComponent(
                                                                                                        jButton1)))
                                                                .addContainerGap(
                                                                        54,
                                                                        Short.MAX_VALUE))
                                                .addGroup(
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        layout.createSequentialGroup()
                                                                .addComponent(
                                                                        jLabel2)
                                                                .addGap(238,
                                                                        238,
                                                                        238)))));
        layout.setVerticalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGap(24, 24,
                                                                        24)
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                .addComponent(
                                                                                        jLabel1)
                                                                                .addComponent(
                                                                                        jTextField1,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGap(22, 22,
                                                                        22)
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addGroup(
                                                                                        layout.createSequentialGroup()
                                                                                                .addGap(5,
                                                                                                        5,
                                                                                                        5)
                                                                                                .addComponent(
                                                                                                        jLabel3))
                                                                                .addGroup(
                                                                                        layout.createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                                                                .addComponent(
                                                                                                        jTextField2,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                                .addComponent(
                                                                                                        jButton1)))))
                                .addGap(36, 36, 36)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jButton2)
                                                .addComponent(jButton3)
                                                .addComponent(jButton4))
                                .addGap(30, 30, 30)
                                .addComponent(jScrollPane1,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        459, Short.MAX_VALUE)
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2).addGap(21, 21, 21)));

        pack();
    }// </editor-fold>
    //GEN-END:initComponents

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {

    }

    //查询按钮的事件监听
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String majorName = jTextField1.getText();
        String mType = jTextField2.getText();
        Major m = new Major(majorName, mType);
        allMajor(m);
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        DeleteMajor();
    }

    //修改按钮
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        UpdateMajor();
    }

    //增加按钮
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        new AddMajorDialog(frame, true).setVisible(true);
        allMajor(null);
    }

    //查询的方法
    public void allMajor(Major m) {
        MajorDao majorDao = new MajorDaoImpl();
        list = majorDao.allMajor(m);

        if (list.size() <= 0) {
            JOptionPane.showMessageDialog(null, "暂时没有该专业信息");
        } else {
            DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
            model.setRowCount(0);
            for (int i = 0; i < list.size(); i++) {
                major = list.get(i);
                Vector rowData = new Vector<>();
                rowData.add(major.getMid());
                rowData.add(major.getmName());
                rowData.add(major.getmType());
                model.addRow(rowData);
            }
            utils.fitTableColumns(jTable1);
        }

    }

    //删除专业的方法
    public void DeleteMajor() {
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "请选择您需要删除专业的信息", "温馨提示",
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            major = list.get(selectedRow);

            ClassDao dao=new ClassDaoImpl();
            List<Class> infoByMid = dao.findClassInfoByMid(major.getMid());
            if(infoByMid.size()<=0){
                MajorDao majorDao = new MajorDaoImpl();
                int i = JOptionPane.showConfirmDialog(null, "是否确认删除专业信息!",
                        "温馨提示", JOptionPane.YES_NO_OPTION);
                if (i == 0) {
                    boolean b = majorDao.deleteMajor(major.getMid());
                    if (b) {
                        JOptionPane.showMessageDialog(null, "删除成功!", "温馨提示",
                                JOptionPane.INFORMATION_MESSAGE);
                        allMajor(null);
                    } else {
                        JOptionPane.showMessageDialog(null, "删除失败!", "温馨提示",
                                JOptionPane.ERROR_MESSAGE);
                    }

                }
            }else{
                JOptionPane.showMessageDialog(null, "该专业下有相应的班级,暂时不能删除!!!", "温馨提示",
                        JOptionPane.ERROR_MESSAGE);
            }

        }

    }

    //修改专业的方法
    public void UpdateMajor() {
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(null, "请选择您需要修改专业的信息", "温馨提示",
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            major = list.get(selectedRow);
            new UpdateMajorDialog(frame, true).setVisible(true);
            allMajor(null);
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
    private List<Major> list;
    public static Major major;

}

角色
RoleInterna.java

/*
 * RoleInterna.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.com.zh.viewInterna;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import cn.com.zh.dao.RoleDao;
import cn.com.zh.dao.RoleDaoImpl;
import cn.com.zh.dialog.AddRoleDialog;
import cn.com.zh.dialog.UpdateRoleDialog;
import cn.com.zh.dialog.ViewMenusByRid;
import cn.com.zh.entity.Role;
import cn.com.zh.entity.User;
import cn.com.zh.util.ViewUtils;

/**
 *
 * @author  __USER__
 */
public class RoleInterna extends javax.swing.JInternalFrame {

    /** Creates new form RoleInterna */
    JFrame frame;
    ViewUtils utils = new ViewUtils();

    public RoleInterna(JFrame frame) {
        this.frame = frame;
        initComponents();
        findAll(null);
        tableMouse();
    }

    public void tableMouse(){
        jTable1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount()==2){
                    int column = jTable1.getSelectedColumn();
                    if(column==3){
                        int row = jTable1.getSelectedRow();
                        Role role2 = list.get(row);
                        new ViewMenusByRid(frame, true,role2).setVisible(true);
                    }
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("\u89d2\u8272\u7ba1\u7406");

        jTable1.setFont(new java.awt.Font("楷体", 1, 18));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] {

                }, new String[] { "角色编号", "角色名称", "角色描述", "查看详细" }) {
            boolean[] canEdit = new boolean[] { false, false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jTable1.setOpaque(false);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setFont(new java.awt.Font("楷体", 1, 18));
        jLabel1.setText("\u89d2\u8272\u540d\u79f0:");

        jButton2.setFont(new java.awt.Font("楷体", 1, 18));
        jButton2.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\addStuBut.png")); // NOI18N
        jButton2.setText("\u589e  \u52a0");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField1.setFont(new java.awt.Font("楷体", 1, 18));

        jButton3.setFont(new java.awt.Font("楷体", 1, 18));
        jButton3.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\StuSure.png")); // NOI18N
        jButton3.setText("\u4fee  \u6539");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("楷体", 1, 18));
        jButton4.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\delete.png")); // NOI18N
        jButton4.setText("\u5220  \u9664");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("楷体", 1, 18));
        jLabel2.setText("\u89d2\u8272\u63cf\u8ff0:");

        jButton1.setFont(new java.awt.Font("楷体", 1, 18));
        jButton1.setIcon(new javax.swing.ImageIcon(
                "D:\\software\\MyEclipse10Packe\\EndDom\\img\\query.png")); // NOI18N
        jButton1.setText("\u67e5  \u8be2");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField2.setFont(new java.awt.Font("楷体", 1, 18));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel1)
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        226,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        30, Short.MAX_VALUE)
                                .addComponent(jLabel2)
                                .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        202,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(33, 33, 33).addComponent(jButton1)
                                .addGap(47, 47, 47))
                .addGroup(
                        layout.createSequentialGroup()
                                .addGap(23, 23, 23)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(
                                                        jScrollPane1,
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        795, Short.MAX_VALUE)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGap(104,
                                                                        104,
                                                                        104)
                                                                .addComponent(
                                                                        jButton2)
                                                                .addGap(80, 80,
                                                                        80)
                                                                .addComponent(
                                                                        jButton3)
                                                                .addGap(92, 92,
                                                                        92)
                                                                .addComponent(
                                                                        jButton4)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                        162,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(38, 38, 38)));
        layout.setVerticalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel1)
                                                .addComponent(jButton1)
                                                .addComponent(jLabel2)
                                                .addComponent(
                                                        jTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(
                                                        jTextField2,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jButton2)
                                                .addComponent(jButton3)
                                                .addComponent(jButton4))
                                .addGap(19, 19, 19)
                                .addComponent(jScrollPane1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        436,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(50, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>
    //GEN-END:initComponents

    //查询语句按钮监听
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String rname = jTextField1.getText();
        String rdesc = jTextField2.getText();

        System.out.println(rname);
        Role r = new Role(rname, rdesc);
        findAll(r);
    }

    //删除按钮
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        deleteRole();
    }

    //修改的方法
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        updateRole();
    }

    //增加角色按钮
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        new AddRoleDialog(frame, true).setVisible(true);
        findAll(null);
    }

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {

    }

    // 查询所有角色用户
    public void findAll(Role r) {
        RoleDao roleDao = new RoleDaoImpl();
        list = roleDao.findall(r);

        if (list.size() <= 0) {
            JOptionPane.showMessageDialog(null, "暂时没有该角色信息", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
            model.setRowCount(0);
            for (int i = 0; i < list.size(); i++) {
                role = list.get(i);
                Vector rowData = new Vector<>();
                rowData.add(role.getRid());
                rowData.add(role.getRname());
                rowData.add(role.getRdesc());
                rowData.add("查       看");
                model.addRow(rowData);
            }
            utils.fitTableColumns(jTable1);
        }
    }

    //删除角色的方法
    public void deleteRole() {
        int row = jTable1.getSelectedRow();

        if (row < 0) {
            JOptionPane.showMessageDialog(null, "请选择你需要删除了角色?", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        role = list.get(row);
        RoleDao roleDao = new RoleDaoImpl();
        int i = JOptionPane.showConfirmDialog(null, "你确认要删除该角色信息吗?", "温馨提示",
                JOptionPane.YES_NO_OPTION);
        if (i == 0) {
            List<User> roleUser = roleDao.findRoleUser(role.getRid());
            if (roleUser.size() <= 0) {
                boolean daleteRole = roleDao.daleteRole(role.getRid());
                if (daleteRole) {
                    JOptionPane.showMessageDialog(null, "删除角色信息成功!", "温馨提示",
                            JOptionPane.INFORMATION_MESSAGE);
                    findAll(null);
                } else {
                    JOptionPane.showMessageDialog(null, "删除角色信息失败!", "温馨提示",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "您需要删除的角色已被用户使用,无法删除",
                        "温馨提示", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //修改的方法
    public void updateRole() {
        int row = jTable1.getSelectedRow();

        if (row < 0) {
            JOptionPane.showMessageDialog(null, "请选择你需要修改角色的信息?", "温馨提示",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            role = list.get(row);
            new UpdateRoleDialog(frame, true).setVisible(true);
            findAll(null);
        }

    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
    private List<Role> list;
    public static Role role;

}

写在最后

如果运行代码中遇到问题,欢迎交流

觉得有用,记得一键三连哦!