首页 > 代码库 > 学生选课系统----TeacherWindow

学生选课系统----TeacherWindow

 

 

/** * @author 李佩 *  * @version v1 *  * @time 2016/12/6 9:29 *  * @program 画出学生选课系统的学生界面 * */package com.csms.windows;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.table.AbstractTableModel;import javax.swing.table.DefaultTableModel;import com.csms.dao.CourseDAO;import com.csms.dao.SelectCourseDAO;import com.csms.dao.TeacherDAO;import com.csms.entity.Course;import com.csms.entity.SelectCourse;import com.csms.entity.Student;import com.csms.entity.Teacher;public class TeacherWindows {	private JFrame frame = new JFrame();	// 设置窗口的宽度	private final int WINDOWWIDE = 220;	// 设置窗口的高度	private final int WINDOWHIGH = 560;	// 老师对象	protected static Teacher teacher = null;	private String backUrl = "src//images//icons//background.jpg";	public TeacherWindows() {		teacher = new TeacherDAO().searchTeacherInformation(LoginWindow.getLoginUserName(),				LoginWindow.getLoginPassword());		this.compnentSet(frame);		PublicWindowSet.windowAttribute(frame, WINDOWWIDE, WINDOWHIGH, backUrl, "老师界面");	}	// 窗口组件设置	private void compnentSet(JFrame jfr) {		// 设置老师照片标签		String url = "src//images//teacher//" + teacher.getTeacID() + ".jpg";		PublicWindowSet.addPhotoLabel(jfr, 55, 70, 105, 140, url);		// 添加老师信息		PublicWindowSet.addLabel(jfr, 13, 115, 218, 110, 50, teacher.getTeacID());		PublicWindowSet.addLabel(jfr, 13, 115, 238, 110, 50, teacher.getTeacName());		PublicWindowSet.addLabel(jfr, 13, 115, 258, 110, 50, Integer.toString(teacher.getTeacAge()));		PublicWindowSet.addLabel(jfr, 13, 115, 278, 110, 50, teacher.getTeacGender());		// 添加按钮		this.addButton(1, 335, "修改密码", jfr);		this.addButton(2, 375, "发布课程", jfr);		this.addButton(3, 415, "删除发布课程", jfr);		this.addButton(4, 455, "录入学生成绩", jfr);		this.addButton(5, 495, "关于", jfr);	}	// 添加老师操作按钮	private void addButton(int flag, int high, String str, JFrame jfr) {		JButton button = new JButton(str);		button.setFont(new Font("楷体", Font.PLAIN, 16));		button.setBounds(35, high, 150, 30);		button.setContentAreaFilled(false);		button.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				switch (flag) {				case 1:					// 修改密码					new TeacherFixPassWordWindows(teacher, jfr);					break;				case 2:					// 发布课程					new ReleaseCourseWindow();					break;				case 3:					new DeleteYourInsertCourse(teacher);					break;				case 4:					// 录入学生成绩					new addStudentGrade();					break;				case 5:					// 关于框					new AboutWindow();					break;				}			}		});		jfr.add(button);	}}// 老师修改密码窗口class TeacherFixPassWordWindows {	private JFrame frame = new JFrame();	private String backURL = "src//images//icons//login.PNG";	public TeacherFixPassWordWindows(Teacher teacher, JFrame jfr) {		showFixPasswordWindow(this.frame, jfr, teacher);		PublicWindowSet.windowAttribute(this.frame, 380, 220, backURL, "密码修改窗口");	}	// 显示窗口	private void showFixPasswordWindow(JFrame fixJFR, JFrame teaJFR, Teacher teacher) {		frame.setLayout(null);		// 1.添加三个标签		// 添加标签		PublicWindowSet.addLabel(frame, 16, 68, 30, 80, 30, "  原密码:");		PublicWindowSet.addLabel(frame, 16, 68, 65, 80, 30, "  新密码:");		PublicWindowSet.addLabel(frame, 16, 68, 100, 80, 30, "重新输入:");		// 2.添加三个文本域		// 添加文本域		JPasswordField oldText = new JPasswordField();		JPasswordField newText = new JPasswordField();		JPasswordField reEText = new JPasswordField();		PublicWindowSet.addTextField(oldText, 160, 30, 150, 30, frame);		PublicWindowSet.addTextField(newText, 160, 65, 150, 30, frame);		PublicWindowSet.addTextField(reEText, 160, 100, 150, 30, frame);		// 3.添加确定按钮		// 添加按钮		Icon icon = new ImageIcon("src//images//icons//confirmFix.png");		JButton confirmBtn = new JButton(icon);		// 设置位置		confirmBtn.setBounds(120, 150, 125, 30);		// 添加进面板		frame.add(confirmBtn);		confirmBtn.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				// 添加修改密码的数据库操作				// 判断输入框是否有内容				if (oldText.getText().length() == 0) {					PublicWindowSet.promptPopUp("请输入原密码", "错误提示", frame);				} else if (newText.getText().length() == 0 || reEText.getText().length() == 0) {					PublicWindowSet.promptPopUp("请输入新密码或重复输入新密码", "错误提示", frame);				}				// 1. 判断原密码输入框的密码是否和元密码相同				if (newText.getText().length() != 0 && reEText.getText().length() != 0						&& !oldText.getText().equals(teacher.getLoginPSD())) {					PublicWindowSet.promptPopUp("原密码输入错误!", "更改密码提示", frame);				}				// 2. 判断新密码和原密码是否输入一致				if (newText.getText().length() != 0 && reEText.getText().length() != 0						&& !reEText.getText().equals(newText.getText())						&& oldText.getText().equals(teacher.getLoginPSD())) {					PublicWindowSet.promptPopUp("两次密码输入不一致!", "更改密码提示", frame);				}				// 3. 更新密码操作				if (newText.getText().length() != 0 && reEText.getText().length() != 0						&& reEText.getText().equals(newText.getText())						&& oldText.getText().equals(teacher.getLoginPSD())) {					new TeacherDAO().updatePassword(teacher.getTeacID(), newText.getText());					// 修改成功释放该窗口					frame.dispose();					// 释放老师窗口					teaJFR.dispose();					// 同时调用出登录窗口					new LoginWindow();				}			}		});	}}// 关于窗口class AboutWindow {	JFrame frame = new JFrame();	private String backURL = "src//images//icons//about.jpg";	public AboutWindow() {		PublicWindowSet.windowAttribute(this.frame, 360, 190, backURL, "关于窗口");	}}// 发布课程窗口class ReleaseCourseWindow {	private JFrame frame = new JFrame();	private JTable table = null;	private String backURL = "src//images//icons//rcourse.jpg";	private static DefaultTableModel tableModel = null;	public ReleaseCourseWindow() {		this.liftInformation();		this.rightList();		PublicWindowSet.windowAttribute(this.frame, 600, 460, backURL, "注册课程");	}	// 右部列表	private void rightList() {		// 设置JTabel的默认类型		this.tableModel = new DefaultTableModel(new CourseInformationList().userInfo,				new CourseInformationList().titles);		// 添加JLabel组件		this.table = new JTable(this.tableModel);		// 禁止JLabel组件随着窗口的大小而改变		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);		// JTabel组件表格的显示尺寸		table.setPreferredScrollableViewportSize(new Dimension(390, 0));		// 使列表不可以整列的进行移动		table.getTableHeader().setReorderingAllowed(false);		// 使列表框不可被编辑		table.enable(false);		// 给JTabel组件添加滑动条		JScrollPane scr = new JScrollPane(this.table);		// 设置面板		JPanel toolBar = new JPanel();		// 将带滚动条的Tabel组件添加入面板的东部区域		frame.add(scr, BorderLayout.EAST);	}	// 左边信息窗口	private void liftInformation() {		PublicWindowSet.addLabel(this.frame, 26, 20, 25, 180, 45, "填写课程信息");		// 添加标签		PublicWindowSet.addLabel(this.frame, 16, 10, 100, 45, 20, "  ID:");		PublicWindowSet.addLabel(this.frame, 16, 10, 135, 45, 20, "课名:");		PublicWindowSet.addLabel(this.frame, 16, 10, 170, 45, 20, "学分:");		PublicWindowSet.addLabel(this.frame, 16, 10, 205, 45, 20, "学时:");		PublicWindowSet.addLabel(this.frame, 16, 10, 240, 45, 20, "类型:");		PublicWindowSet.addLabel(this.frame, 16, 10, 273, 45, 20, "老师:");		PublicWindowSet.addLabel(this.frame, 16, 10, 307, 45, 20, "人数:");		// 添加文本框		// 一个容器,保存下面的对象		List<JTextField> list = new ArrayList<JTextField>();		JTextField id = new JTextField();		JTextField name = new JTextField();		JTextField cridits = new JTextField();		JTextField time = new JTextField();		JTextField type = new JTextField();		JTextField teac = new JTextField();		JTextField number = new JTextField();		PublicWindowSet.addTextField(id, 60, 95, 100, 30, this.frame);		PublicWindowSet.addTextField(name, 60, 130, 100, 30, this.frame);		PublicWindowSet.addTextField(cridits, 60, 165, 100, 30, this.frame);		PublicWindowSet.addTextField(time, 60, 200, 100, 30, this.frame);		PublicWindowSet.addTextField(type, 60, 235, 100, 30, this.frame);		PublicWindowSet.addTextField(teac, 60, 270, 100, 30, this.frame);		PublicWindowSet.addTextField(number, 60, 305, 100, 30, this.frame);		list.add(id);		list.add(name);		list.add(cridits);		list.add(time);		list.add(type);		list.add(teac);		list.add(number);		// 添加确认button		this.addButton(1, 350, "确认提交", list, TeacherWindows.teacher);		this.addButton(2, 390, "已注册课程", list, TeacherWindows.teacher);	}	// 添加button	private void addButton(int flag, int high, String str, List<JTextField> l, Teacher teacher) {		JButton confrim = new JButton(str);		confrim.setFont(new Font("楷体", Font.PLAIN, 16));		confrim.setBounds(40, high, 120, 35);		confrim.setContentAreaFilled(false);		frame.add(confrim);		confrim.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				switch (flag) {				case 1:					if (l.get(0).getText().length() == 0 || l.get(1).getText().length() == 0							|| l.get(2).getText().length() == 0 || l.get(3).getText().length() == 0							|| l.get(4).getText().length() == 0 || l.get(5).getText().length() == 0							|| l.get(6).getText().length() == 0)						PublicWindowSet.promptPopUp("请填写完整的课程信息!", "录入课程提示", frame);					else {						new CourseDAO().insertCourseInformation(l, teacher);						for (int i = 0; i < l.size(); i++) {							l.get(i).setText("");						}					}					break;				case 2:					List<Course> list = new CourseDAO().searchCourseInformation();					Course course = null;					for (int i = 0; i < list.size(); i++) {						course = list.get(i);						ReleaseCourseWindow.tableModel.addRow(new Object[] { i, course.getCourID(),								course.getCourName(), course.getCourTeacher(), course.getCourType() });					}					confrim.setEnabled(false);					break;				}			}		});	}	// JTabel列表属性设置类	class CourseInformationList extends AbstractTableModel {		public String[] titles = { "序号", "课程ID", "课程名", "老师", "类型" };		public Object[][] userInfo = {}; // 定义数据		public int getRowCount() {			return 0;		}		public int getColumnCount() {			return 0;		}		public Object getValueAt(int rowIndex, int columnIndex) {			return null;		}	}}// 删除插入的课程class DeleteYourInsertCourse {	private JFrame frame = new JFrame();	private JFrame coursePopUpJFR = null;	private String url = "src//images//icons//admin.jpg";	private String[] courseStr = { "课程ID", "课程名", "学分", "学时", "人数" };	private static DefaultTableModel courseTableModel;	JTextField courseID = null;	public DeleteYourInsertCourse(Teacher teacher) {		this.windowInformation(teacher);		PublicWindowSet.windowAttribute(this.frame, 400, 170, url, "删除注册课程");	}	private void windowInformation(Teacher teacher) {		// 添加大标签		PublicWindowSet.addLabel(frame, 26, 110, 5, 300, 30, "删除注册课程");		// 添加小标签		PublicWindowSet.addLabel(frame, 16, 45, 55, 90, 30, "  课程ID:");		// 添加button		this.addButton(1, frame, 55, "查看注册课程", teacher, this);		this.addButton(2, frame, 205, "删除注册课程", teacher, this);		// 添加文本域		courseID = new JTextField();		PublicWindowSet.addTextField(courseID, 130, 55, 200, 30, this.frame);	}	public void showCourseWindow(Teacher teacher) {		coursePopUpJFR = new JFrame();		PublicWindowSet.windowAttribute(coursePopUpJFR, 400, 200, null, "学生信息窗口");		courseTableModel = PublicWindowSet.addTableList(coursePopUpJFR, courseStr);		List<Course> list = new CourseDAO().searchCourse(teacher.getTeacID());		Course course = null;		for (int i = 0; i < list.size(); i++) {			course = list.get(i);			courseTableModel.addRow(new Object[] { course.getCourID(), course.getCourName(), course.getCourCridits(),					course.getCourTimes(), course.getCourNumber() });		}	}	private void addButton(int flag, JFrame jfr, int x, String str, Teacher teacher, DeleteYourInsertCourse dyi) {		JButton button = new JButton(str);		button.setFont(new Font("楷体", Font.PLAIN, 16));		button.setContentAreaFilled(false);		button.setBounds(x, 100, 140, 30);		button.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				switch (flag) {				case 1:					dyi.showCourseWindow(teacher);					break;				case 2:					if (courseID.getText().length() != 0) {						new CourseDAO().deleteCourseInformation(courseID.getText());						coursePopUpJFR.dispose();						courseID.setText("");						dyi.showCourseWindow(teacher);					} else						PublicWindowSet.promptPopUp("请填写要删除的课程ID!", "删除课程提示", jfr);					break;				}			}		});		jfr.add(button);	}}// 录入学生成绩class addStudentGrade {	JFrame frame = new JFrame();	private DefaultTableModel gradeTableModel;	private JFrame popUpJFR = null;	private String courseID = null;	private JTextField courseText = null;	private JTextField gradeText = null;	private JTextField studentText = null;	private String url = "src//images//icons//admin.jpg";	private String[] gradeStr = { "课程ID", "课程名称", "任课老师", "学生ID", "学生姓名", "课程成绩" };	public addStudentGrade() {		this.displayInformation(frame);	}		// 老师显示信息	private void displayInformation(JFrame jfr) {		PublicWindowSet.addLabel(jfr, 26, 110, 5, 300, 30, "学生成绩录入");		PublicWindowSet.addLabel(jfr, 16, 45, 55, 90, 30, "  课程ID:");		courseText = new JTextField();		PublicWindowSet.addTextField(courseText, 130, 55, 200, 30, jfr);		PublicWindowSet.addLabel(jfr, 16, 45, 90, 90, 30, "  学生ID:");		studentText = new JTextField();		PublicWindowSet.addTextField(studentText, 130, 90, 200, 30, jfr);		PublicWindowSet.addLabel(jfr, 16, 45, 125, 90, 30, "课程成绩:");		gradeText = new JTextField();		PublicWindowSet.addTextField(gradeText, 130, 125, 200, 30, jfr);		addButton(1, jfr, "选课学生", 75, this);		addButton(2, jfr, "添加成绩", 210, this);		PublicWindowSet.windowAttribute(jfr, 380, 235, url, "老师界面");	}	// 学生信息显示窗口	private void showInformation() {		popUpJFR = new JFrame();		PublicWindowSet.windowAttribute(popUpJFR, 475, 200, null, "学生信息窗口");		gradeTableModel = PublicWindowSet.addTableList(popUpJFR, gradeStr);		courseID = courseText.getText();		List<Object> list = new SelectCourseDAO().searchUnionInformation(courseID);		for (int i = 0; i < list.size(); i = i + 3) {			Course course = (Course) list.get(i);			Student student = (Student) list.get(i + 1);			SelectCourse sc = (SelectCourse) list.get(i + 2);			gradeTableModel.addRow(new Object[] { course.getCourID(), course.getCourName(), course.getCourTeacher(),					student.getStuID(), student.getStuName(), sc.getStudentGrade() });		}	}	private void addButton(int flag, JFrame jfr, String str, int x, addStudentGrade th) {		JButton button = new JButton(str);		button.setFont(new Font("楷体", Font.PLAIN, 16));		button.setContentAreaFilled(false);		button.setBounds(x, 170, 100, 30);		button.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				switch (flag) {				case 1:					if (courseText.getText().length() == 0) {						PublicWindowSet.promptPopUp("请先输入课程ID,在查看选修的学生", "错误提示", jfr);					} else {						th.showInformation();					}					break;				case 2:					if (courseText.getText().length() == 0) {						PublicWindowSet.promptPopUp("请先输入课程ID,在录入学生成绩", "错误提示", jfr);					}					if (courseText.getText().length() != 0 && studentText.getText().length() == 0) {						PublicWindowSet.promptPopUp("请先输入学生ID,在录入学生成绩", "错误提示", jfr);					}					if (courseText.getText().length() != 0 && studentText.getText().length() != 0							&& gradeText.getText().length() == 0) {						PublicWindowSet.promptPopUp("请学生成绩,在录入成绩", "错误提示", jfr);					} else {						new SelectCourseDAO().addStudentGrade(studentText.getText(), courseText.getText(),								Float.valueOf(gradeText.getText()));						studentText.setText("");						gradeText.setText("");						popUpJFR.dispose();						th.showInformation();					}					break;				}			}		});		jfr.add(button);	}}

  

 

学生选课系统----TeacherWindow