/** * @author 李佩 * * @version v1 * * @time 2016/12/7 9:37 * * @program 创建对应数据表实体的老师类,方便dao与数据库的连接 * */ package com.csms.windows; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; import com.csms.dao.AdminitartorDAO; import com.csms.dao.CourseArrangeDAO; import com.csms.dao.StudentDAO; import com.csms.dao.TeacherDAO; import com.csms.entity.Adminitartor; import com.csms.entity.Course; import com.csms.entity.CourseArrange; import com.csms.entity.Student; import com.csms.entity.Teacher; public class AdmintratorWindow { private static final int WINDOWWIDE = 200; private static final int WINDOWHIGH = 670; private static Adminitartor admin = null; String userName = LoginWindow.getLoginUserName(); String userPsd = LoginWindow.getLoginPassword(); String url = "src//images//icons//admin.jpg"; private JFrame frame = new JFrame(); public AdmintratorWindow() { admin = this.getAdminitratorInformation(); this.informationArea(frame); PublicWindowSet.windowAttribute(frame, WINDOWWIDE, WINDOWHIGH, url, "管理员窗口"); } public void informationArea(JFrame jfr) { // 大标题 PublicWindowSet.addLabel(jfr, 26, 30, 10, 150, 30, "管理员信息"); // 管理员照片 String url = "src//images//adiminitrator//" + admin.getAdminID() + ".jpg"; PublicWindowSet.addPhotoLabel(jfr, 50, 70, 100, 130, url); // 管理员标签信息 PublicWindowSet.addLabel(jfr, 16, 20, 240, 100, 15, " ID:"); PublicWindowSet.addLabel(jfr, 16, 20, 270, 100, 15, "姓名:"); PublicWindowSet.addLabel(jfr, 16, 20, 300, 100, 15, "年龄:"); PublicWindowSet.addLabel(jfr, 16, 20, 330, 100, 15, "性别:"); PublicWindowSet.addLabel(jfr, 16, 20, 360, 100, 15, "手机:"); PublicWindowSet.addLabel(jfr, 16, 20, 390, 100, 15, "住址:"); // 管理员界面功能按钮 addButton(1, "发布学生信息", 440, jfr); addButton(2, "发布老师信息", 480, jfr); addButton(3, "发布排课信息", 520, jfr); addButton(4, "删除信息", 560, jfr); addButton(5, "退出", 600, jfr); // 添加管理员的详细信息 PublicWindowSet.addLabel(jfr, 16, 65, 240, 100, 15, admin.getAdminID()); PublicWindowSet.addLabel(jfr, 16, 65, 270, 100, 15, admin.getAdminName()); PublicWindowSet.addLabel(jfr, 16, 65, 300, 100, 15, Integer.toString(admin.getAdminAge())); PublicWindowSet.addLabel(jfr, 16, 65, 330, 100, 15, admin.getAdminGender()); PublicWindowSet.addLabel(jfr, 16, 65, 360, 100, 15, admin.getAdminPhone()); PublicWindowSet.addLabel(jfr, 16, 65, 390, 100, 15, admin.getAdminAddress()); } // 添加button private static void addButton(int flag, String str, int high, JFrame frm) { JButton button = new JButton(str); button.setFont(new Font("楷体", Font.PLAIN, 16)); button.setBounds(30, high, 130, 30); button.setContentAreaFilled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { switch (flag) { case 1: // 发布录入学生信息 new releaseStudentInformationWindow(); break; case 2: // 发布录入老师信息 new releaseTeacherInformationWindow(); break; case 3: // 发布排课信息 new releaseCourseInformationWindow(); break; case 4: // 删除信息 new deleteInformationWindow(); break; case 5: // 退出 frm.dispose(); break; } } }); frm.add(button); } // 取得管理员的所有信息 public Adminitartor getAdminitratorInformation() { return new AdminitartorDAO().getInformation(userName, userPsd); } } // 发布学生信息 class releaseStudentInformationWindow { private JFrame frame = new JFrame(); String url = "src//images//icons//admin.jpg"; public releaseStudentInformationWindow() { this.displayInformation(this.frame); } private void displayInformation(JFrame jfr) { PublicWindowSet.addLabel(jfr, 26, 35, 10, 170, 30, "学生信息录入"); PublicWindowSet.addLabel(jfr, 16, 20, 70, 90, 30, " 登录名:"); PublicWindowSet.addLabel(jfr, 16, 20, 100, 90, 30, "登录密码:"); PublicWindowSet.addLabel(jfr, 16, 20, 130, 90, 30, "学生姓名:"); PublicWindowSet.addLabel(jfr, 16, 20, 160, 90, 30, " 学生ID:"); PublicWindowSet.addLabel(jfr, 16, 20, 190, 90, 30, "学生年龄:"); PublicWindowSet.addLabel(jfr, 16, 20, 220, 90, 30, "学生性别:"); PublicWindowSet.addLabel(jfr, 16, 20, 250, 90, 30, "学生院系:"); PublicWindowSet.addLabel(jfr, 16, 20, 280, 90, 30, "学生班级:"); JTextField userName = new JTextField(); PublicWindowSet.addTextField(userName, 100, 70, 120, 25, jfr); JTextField userPsd = new JTextField(); PublicWindowSet.addTextField(userPsd, 100, 100, 120, 25, jfr); JTextField name = new JTextField(); PublicWindowSet.addTextField(name, 100, 130, 120, 25, jfr); JTextField id = new JTextField(); PublicWindowSet.addTextField(id, 100, 160, 120, 25, jfr); JTextField age = new JTextField(); PublicWindowSet.addTextField(age, 100, 190, 120, 25, jfr); JTextField gender = new JTextField(); PublicWindowSet.addTextField(gender, 100, 220, 120, 25, jfr); JTextField sdept = new JTextField(); PublicWindowSet.addTextField(sdept, 100, 250, 120, 25, jfr); JTextField cla = new JTextField(); PublicWindowSet.addTextField(cla, 100, 280, 120, 25, jfr); JButton button = new JButton("确定录入"); button.setBounds(75, 330, 100, 30); button.setFont(new Font("楷体", Font.PLAIN, 16)); button.setContentAreaFilled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Student student = new Student(); // 登录名 student.setLoginName(userName.getText()); // 登录密码 student.setLoginPSD(userPsd.getText()); // 学生姓名 student.setStuName(name.getText()); // 学生id student.setStuID(id.getText()); // 学生年龄 student.setStuAge(Integer.valueOf(age.getText())); // 学生性别 student.setStuGender(gender.getText()); // 学生系院 student.setStuSdept(sdept.getText()); // 学生班级 student.setStuClass(cla.getText()); new StudentDAO().insertStudentInformation(student); userName.setText(""); userPsd.setText(""); name.setText(""); id.setText(""); age.setText(""); gender.setText(""); sdept.setText(""); cla.setText(""); } }); jfr.add(button); PublicWindowSet.windowAttribute(this.frame, 250, 400, url, "发布学生信息"); } } // 录入老师信息 class releaseTeacherInformationWindow { String url = "src//images//icons//admin.jpg"; private JFrame frame = new JFrame(); public releaseTeacherInformationWindow() { this.displayInformation(frame); } private void displayInformation(JFrame jfr) { // 添加老师信息界面的标签组 PublicWindowSet.addLabel(jfr, 26, 35, 10, 170, 30, "老师信息录入"); PublicWindowSet.addLabel(jfr, 16, 20, 70, 90, 30, " 登录名:"); PublicWindowSet.addLabel(jfr, 16, 20, 100, 90, 30, "登录密码:"); PublicWindowSet.addLabel(jfr, 16, 20, 130, 90, 30, "老师姓名:"); PublicWindowSet.addLabel(jfr, 16, 20, 160, 90, 30, " 老师ID:"); PublicWindowSet.addLabel(jfr, 16, 20, 190, 90, 30, "老师年龄:"); PublicWindowSet.addLabel(jfr, 16, 20, 220, 90, 30, "老师性别:"); // 添加老师信息界面的文本框组 JTextField userName = new JTextField(); PublicWindowSet.addTextField(userName, 100, 70, 120, 25, jfr); JTextField userPsd = new JTextField(); PublicWindowSet.addTextField(userPsd, 100, 100, 120, 25, jfr); JTextField name = new JTextField(); PublicWindowSet.addTextField(name, 100, 130, 120, 25, jfr); JTextField id = new JTextField(); PublicWindowSet.addTextField(id, 100, 160, 120, 25, jfr); JTextField age = new JTextField(); PublicWindowSet.addTextField(age, 100, 190, 120, 25, jfr); JTextField gender = new JTextField(); PublicWindowSet.addTextField(gender, 100, 220, 120, 25, jfr); JButton button = new JButton("确定录入"); button.setBounds(75, 270, 100, 30); button.setFont(new Font("楷体", Font.PLAIN, 16)); button.setContentAreaFilled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Teacher teacher = new Teacher(); // 取得文本框中输入的内容 teacher.setLoginName(userName.getText()); teacher.setLoginPSD(userPsd.getText()); teacher.setTeacName(name.getText()); teacher.setTeacID(id.getText()); teacher.setTeacAge(Integer.valueOf(age.getText())); teacher.setTeacGender(gender.getText()); // 将新添加的信息插入数据库 new TeacherDAO().insertInformation(teacher); // 插完之后将文本框内容清空 userName.setText(""); userPsd.setText(""); name.setText(""); id.setText(""); age.setText(""); gender.setText(""); } }); jfr.add(button); // 窗口属性设置 PublicWindowSet.windowAttribute(this.frame, 250, 340, url, "发布老师信息"); } } // 录入排课信息 class releaseCourseInformationWindow { private JFrame frame = new JFrame(); String url = "src//images//icons//admin.jpg"; private void displayInformation(JFrame jfr) { PublicWindowSet.addLabel(jfr, 26, 35, 10, 170, 30, "排课信息录入"); PublicWindowSet.addLabel(jfr, 16, 20, 70, 90, 30, "课程ID:"); PublicWindowSet.addLabel(jfr, 16, 20, 100, 90, 30, "任课老师:"); PublicWindowSet.addLabel(jfr, 16, 20, 130, 90, 30, "课程名称:"); PublicWindowSet.addLabel(jfr, 16, 20, 160, 90, 30, "课程学分:"); PublicWindowSet.addLabel(jfr, 16, 20, 190, 90, 30, "课程学时:"); PublicWindowSet.addLabel(jfr, 16, 20, 220, 90, 30, "课程类型:"); PublicWindowSet.addLabel(jfr, 16, 20, 250, 90, 30, "课程人数:"); PublicWindowSet.addLabel(jfr, 16, 20, 280, 90, 30, "已选人数:"); PublicWindowSet.addLabel(jfr, 16, 20, 310, 90, 30, "课程安排:"); JTextField courID = new JTextField(); PublicWindowSet.addTextField(courID, 100, 70, 120, 25, jfr); JTextField teac = new JTextField(); PublicWindowSet.addTextField(teac, 100, 100, 120, 25, jfr); JTextField name = new JTextField(); PublicWindowSet.addTextField(name, 100, 130, 120, 25, jfr); JTextField cridits = new JTextField(); PublicWindowSet.addTextField(cridits, 100, 160, 120, 25, jfr); JTextField times = new JTextField(); PublicWindowSet.addTextField(times, 100, 190, 120, 25, jfr); JTextField type = new JTextField(); PublicWindowSet.addTextField(type, 100, 220, 120, 25, jfr); JTextField number = new JTextField(); PublicWindowSet.addTextField(number, 100, 250, 120, 25, jfr); JTextField selectNumber = new JTextField(); PublicWindowSet.addTextField(selectNumber, 100, 280, 120, 25, jfr); JTextField arrange = new JTextField(); PublicWindowSet.addTextField(arrange, 100, 310, 120, 25, jfr); JButton button = new JButton("确定录入"); button.setBounds(75, 350, 100, 30); button.setFont(new Font("楷体", Font.PLAIN, 16)); button.setContentAreaFilled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CourseArrange ca = new CourseArrange(); ca.setCourseID(courID.getText()); ca.setCourseTeacher(teac.getText()); ca.setCourseName(name.getText()); ca.setCourseGridits(Integer.valueOf(cridits.getText())); ca.setCourseTimes(Integer.valueOf(times.getText())); ca.setCourseType(type.getText()); ca.setCourseNumber(Integer.valueOf(number.getText())); ca.setCourseSelectNumber(Integer.valueOf(selectNumber.getText())); ca.setCourseArrange(arrange.getText()); new CourseArrangeDAO().insertCourseArrange(ca); courID.setText(""); teac.setText(""); name.setText(""); cridits.setText(""); times.setText(""); type.setText(""); number.setText(""); selectNumber.setText(""); arrange.setText(""); } }); jfr.add(button); PublicWindowSet.windowAttribute(this.frame, 250, 420, url, "发布排课信息"); } public releaseCourseInformationWindow() { this.displayInformation(frame); } } // 删除信息 class deleteInformationWindow { private JFrame frame = new JFrame(); String url = "src//images//icons//admin.jpg"; public deleteInformationWindow() { this.displayInformation(frame); } private void displayInformation(JFrame jfr) { // 添加分类大标签 PublicWindowSet.addLabel(jfr, 26, 40, 10, 170, 30, "删除学生信息"); PublicWindowSet.addLabel(jfr, 26, 40, 220, 170, 30, "删除老师信息"); PublicWindowSet.addLabel(jfr, 26, 40, 430, 170, 30, "删除课程信息"); // 添加学生信息 PublicWindowSet.addLabel(jfr, 16, 20, 70, 90, 30, "学生ID:"); JTextField stuIDField = new JTextField(); PublicWindowSet.addTextField(stuIDField, 85, 70, 125, 25, jfr); this.addButton(1, "查看学生信息", 115, this.frame, stuIDField); this.addButton(2, "删除学生信息", 150, this.frame, stuIDField); // 添加学生信息 PublicWindowSet.addLabel(jfr, 16, 20, 280, 90, 30, "老师ID:"); JTextField teaIDField = new JTextField(); PublicWindowSet.addTextField(teaIDField, 85, 280, 125, 25, jfr); this.addButton(3, "查看老师信息", 325, this.frame, teaIDField); this.addButton(4, "删除老师信息", 360, this.frame, teaIDField); // 添加学生信息 PublicWindowSet.addLabel(jfr, 16, 20, 490, 90, 30, "课程ID:"); JTextField couIDField = new JTextField(); PublicWindowSet.addTextField(couIDField, 85, 490, 125, 25, jfr); this.addButton(5, "查看课程信息", 535, this.frame, couIDField); this.addButton(6, "删除课程信息", 570, this.frame, couIDField); // 设置窗口属性 PublicWindowSet.windowAttribute(jfr, 250, 640, url, "信息删除窗口"); } public void addButton(int flag, String str, int high, JFrame jfr, JTextField tf) { JButton button = new JButton(str); button.setFont(new Font("楷体", Font.PLAIN, 16)); button.setContentAreaFilled(false); button.setBounds(50, high, 150, 30); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { switch (flag) { case 1: // 查看学生信息 DefaultTableModel stuTableModel; String[] stuStr = { "学生ID", "学生姓名", "学生年龄", "学生性别", "学生院系", "学生班级" }; JFrame stuFrame = new JFrame(); PublicWindowSet.windowAttribute(stuFrame, 480, 400, null, "学生信息"); stuTableModel = PublicWindowSet.addTableList(stuFrame, stuStr); List<Student> stuList = new StudentDAO().searchAllStudent(); Student student = null; for (int i = 0; i < stuList.size(); i++) { student = stuList.get(i); System.out.println(student.getStuSdept() + student.getStuClass()); stuTableModel .addRow(new Object[] { student.getStuID(), student.getStuName(), student.getStuAge(), student.getStuGender(), student.getStuSdept(), student.getStuClass() }); } break; case 2: // 删除学生信息 String stuId = tf.getText(); if (stuId.length() == 0) { PublicWindowSet.promptPopUp("请输入学生ID!!!", "错误提示", jfr); } else { new StudentDAO().deleteStudentInformation(stuId); tf.setText(""); } break; case 3: // 查看老师信息 DefaultTableModel teaTableModel; String[] teaStr = { "老师ID", "老师姓名", "老师年龄", "老师性别" }; JFrame teaFrame = new JFrame(); PublicWindowSet.windowAttribute(teaFrame, 330, 400, null, "老师信息"); teaTableModel = PublicWindowSet.addTableList(teaFrame, teaStr); Teacher teacher = null; // 执行查询操作 List<Teacher> teacList = new TeacherDAO().searchAllTeacherInformation(); for (int i = 0; i < teacList.size(); i++) { teacher = teacList.get(i); // 将信息添加至Table组件 teaTableModel.addRow(new Object[] { teacher.getTeacID(), teacher.getTeacName(), teacher.getTeacAge(), teacher.getTeacGender() }); } break; case 4: // 删除老师信息 String teaId = tf.getText(); if (teaId.length() == 0) { PublicWindowSet.promptPopUp("请输入老师ID!!!", "错误提示", jfr); } else { new TeacherDAO().deleteTeacherInformation(teaId); tf.setText(""); } break; case 5: // 查看排课信息 DefaultTableModel courTableModel; String[] courStr = { "课程ID", "任课老师", "课程名字", "课程学分", "课程学时", "课程类型", "课程人数", "已选人数", "课程安排" }; JFrame courFrame = new JFrame(); PublicWindowSet.windowAttribute(courFrame, 700, 400, null, "排课信息"); courTableModel = PublicWindowSet.addTableList(courFrame, courStr); List<CourseArrange> courseList = new CourseArrangeDAO().searchAllCourseArrange(); CourseArrange courseArrange = null; for (int i = 0; i < courseList.size(); i++) { courseArrange = courseList.get(i); courTableModel.addRow(new Object[] { courseArrange.getCourseID(), courseArrange.getCourseTeacher(), courseArrange.getCourseName(), courseArrange.getCourseGridits(), courseArrange.getCourseTimes(), courseArrange.getCourseType(), courseArrange.getCourseNumber(), courseArrange.getCourseSelectNumber(), courseArrange.getCourseArrange() }); } break; case 6: // 删除排课信息 String arrangeId = tf.getText(); if (arrangeId.length() == 0) { PublicWindowSet.promptPopUp("请输入课程ID!!!", "错误提示", jfr); } else { new CourseArrangeDAO().deleteArrageCourseInformation(arrangeId); tf.setText(""); } break; } } }); jfr.add(button); } }
时间: 2024-11-06 23:35:07