⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentinfopanel.java

📁 Java写的一个学员系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		this.getJTName().setEnabled(value);
		this.getJTNumber().setEnabled(value);
		this.getJCSex().setSelectedIndex(0);
		this.getJCSex().setEnabled(value);
		this.getJTMingZhu().setEnabled(value);
		this.getJTBirthday().setEnabled(value);
		this.getJTAddress().setEnabled(value);
		this.getJTFatherName().setEnabled(value);
		this.getJTMotherName().setEnabled(value);
		this.getJTFatherPhone().setEnabled(value);
		this.getJTMotherPhone().setEnabled(value);
		this.getJTZip().setEnabled(value);
		this.getJTJiGuan().setEnabled(value);
		this.getJTZhuangYe().setEnabled(value);
		this.getJTBanJi().setEnabled(value);
	}

	public void actionPerformed(ActionEvent arg0) {
		String arg = arg0.getActionCommand();
		if (arg.trim().equals("new")) {
			this.enableJText(true);
			this.setJTextNullValue();
			this.getJBNew().setActionCommand("newEnter");
			this.getJBNew().setText("确定");

			this.getJBModify().setActionCommand("modify");
			this.getJBModify().setText("修改");

			this.getJBDelete().setEnabled(false);
			this.getJBModify().setEnabled(false);

		} else if (arg.trim().equals("newEnter")) {
			this.getJBNew().setActionCommand("new");
			this.getJBNew().setText("添加");

			newModifyDeleteStudent(new StudentInfo(), "new");

			this.enableJText(false);
			this.setProcessButtonEnable(true);

			this.initComponents();

		} else if (arg.trim().equals("modify")) {
			this.setEnabled(true);
			this.getJBModify().setActionCommand("modifyEnter");
			this.getJBModify().setText("确定");

			this.getJBNew().setActionCommand("new");
			this.getJBNew().setText("添加");

			this.getJBNew().setEnabled(false);
			this.getJBDelete().setEnabled(false);
			this.enableJText(true);

		} else if (arg.trim().equals("modifyEnter")) {
			this.getJBModify().setActionCommand("modify");
			this.getJBModify().setText("修改");

			this.enableJText(false);
			this.setProcessButtonEnable(true);
			this.newModifyDeleteStudent(this.stuInfo, "modify");

			this.initComponents();
		} else if (arg.trim().equals("delete")) {
			// 删除
			this.setProcessButtonEnable(true);

			this.newModifyDeleteStudent(this.stuInfo, "delete");

			this.initComponents();
		} else if (arg.trim().equals("<")) {
			count = 0;
			this.stuInfo = list.get(0);
			this.initStudentInfoText(stuInfo);
			this.getJBBackUp().setEnabled(false);
			this.jBFirst.setEnabled(false);
			this.getJBNext().setEnabled(true);
			this.getJBLast().setEnabled(true);
			if (list.size() == 1) {
				this.getJBNext().setEnabled(false);
				this.getJBLast().setEnabled(false);
			}

			this.getJPChengJi().setVisible(false);
		} else if (arg.trim().equals(">")) {
			count = list.size() - 1;
			this.stuInfo = list.get(count);
			this.initStudentInfoText(stuInfo);
			this.getJBNext().setEnabled(false);
			this.getJBLast().setEnabled(false);
			this.getJBBackUp().setEnabled(true);
			this.getJBFirst().setEnabled(true);

			this.getJPChengJi().setVisible(false);
		} else if (arg.trim().equals("<<")) {
			count -= 1;
			if (count > 0) {
				this.stuInfo = list.get(count);
				this.initStudentInfoText(stuInfo);

			} else if (count == 0) {
				this.getJBBackUp().setEnabled(false);
				this.stuInfo = list.get(count);
				this.initStudentInfoText(stuInfo);
			}
			this.getJBNext().setEnabled(true);
			this.getJBFirst().setEnabled(true);
			this.getJBLast().setEnabled(true);

			this.getJPChengJi().setVisible(false);
		} else if (arg.trim().equals(">>")) {
			count += 1;
			if (count < this.list.size()) {
				this.stuInfo = list.get(count);
				this.initStudentInfoText(stuInfo);
				this.getJBBackUp().setEnabled(true);
				this.getJBFirst().setEnabled(true);
			}
			if (count == list.size() - 1) {
				this.getJBNext().setEnabled(false);
				this.getJBLast().setEnabled(false);
			}

			this.getJPChengJi().setVisible(false);
		} else if (arg.trim().equals(this.CHENG_JI_MANAGE)) {
			this.jPChengJi.setVisible(true);
			// 构造课程列表
			// 构造成绩表
			initJTable(this.stuInfo);
		} else if (arg.trim().equals(NEW_CJ)) {
			// 使能控件
			this.enableChengJiComponet(true);
			this.getJBNewChengJi().setText("确定");
			this.getJBNewChengJi().setActionCommand(NEW_CJ_ENTER);

			this.getJBModifyChengJi().setEnabled(false);
			this.getJBDeleteChengJi().setEnabled(false);

		} else if (arg.trim().equals(NEW_CJ_ENTER)) {
			this.enableChengJiComponet(false);
			this.getJBNewChengJi().setText("添加成绩");
			this.getJBNewChengJi().setActionCommand(NEW_CJ);

			this.getJBModifyChengJi().setEnabled(true);
			this.getJBDeleteChengJi().setEnabled(true);

			this.addChengJi();
			this.initJTable(this.stuInfo);

		} else if (arg.trim().equals(MODIFY_CJ)) {
			this.enableChengJiComponet(false);
			this.getJBModifyChengJi().setText("确定");
			this.getJBModifyChengJi().setActionCommand(MODIFY_CJ_ENTER);

			this.getJTChengJi().setEnabled(true);
			this.getJTRemark().setEnabled(true);
			this.getJBNewChengJi().setEnabled(false);
			this.getJBDeleteChengJi().setEnabled(false);

		} else if (arg.trim().equals(MODIFY_CJ_ENTER)) {

			this.enableChengJiComponet(false);
			this.getJBModifyChengJi().setText("修改成绩");
			this.getJBModifyChengJi().setActionCommand(MODIFY_CJ);

			this.getJBNewChengJi().setEnabled(true);
			this.getJBDeleteChengJi().setEnabled(true);


			this.modifyChengJi();
			this.initJTable(this.stuInfo);

		} else if (arg.trim().equals(DELETE_CJ)) {
			this.enableChengJiComponet(false);
			this.deleteChengJi();
			this.initJTable(this.stuInfo);
		} else if(arg.trim().equals(CALENDAL)) {
			CalendarDialog cd = new CalendarDialog(null, this);
			cd.setVisible(false);
			cd.setVisible(true);
		}
	}

	private void enableChengJiComponet(boolean value) {
		this.getJCKeChengName().setEnabled(value);
		this.getJTChengJi().setEnabled(value);
		this.getJTKeChengNum().setEnabled(value);
		this.getJTRemark().setEnabled(value);
	}

	/**
	 * 根据学生信息构造成绩表格
	 *
	 * @param stuInfo
	 */
	private void initJTable(StudentInfo stuInfo) {
		String[] column = { "课程名称", "课程号", "成绩", "备注" };

		List<KeMuChengJi> list = this.otherUtil.getKeMuChengJis(stuInfo);
		Object[][] object = new Object[list.size()][column.length];
		for (int i = 0; i < list.size(); i++) {
			this.keMuChengJi = list.get(i);
			object[i][0] = keMuChengJi.getCi().getName();
			object[i][1] = keMuChengJi.getCi().getNumber();
			object[i][2] = keMuChengJi.getChengJi();
			object[i][3] = keMuChengJi.getRemark();
		}
		this.getJTable().setModel(new DefaultTableModel(object, column));
		this.getJScrollPane().setVisible(false);
		this.getJScrollPane().setVisible(true);
	}

	/**
	 * 添加、删除、修改一个studentInfo对象
	 *
	 * @param stuInfo
	 *            一个studentInfo对象
	 * @param processType
	 *            操作类型,下列值之一:new, modify, delete
	 */
	private void newModifyDeleteStudent(StudentInfo stuInfo, String processType) {
		ObjectContainer oc = DataBaseConnector.getDb();
		try {
			if (processType.trim().equals("delete")) {
				ObjectSet result = oc.get(stuInfo);
				this.stuInfo = (StudentInfo) result.next();
				oc.delete(this.stuInfo);

			} else if (processType.trim().equals("modify")) {
				ObjectSet result = oc.get(stuInfo);
				this.stuInfo = (StudentInfo) result.next();
				this.stuInfo = this.builderStudentInfoByUI(stuInfo);
				oc.set(this.stuInfo);

			} else {
				stuInfo = this.builderStudentInfoByUI(stuInfo);
				oc.set(stuInfo);
			}
			oc.commit();
			oc.close();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			oc.rollback();
			oc.close();
		}
	}

	/**
	 * 设置添加、删除、修改按钮的使能状态
	 *
	 * @param value
	 */
	private void setProcessButtonEnable(boolean value) {
		this.getJBNew().setEnabled(value);
		this.getJBDelete().setEnabled(value);
		this.getJBModify().setEnabled(value);
	}

	/**
	 * 根据UI里的值构造一个学生对象
	 *
	 * @param student
	 * @return
	 * @throws ParseException
	 */
	private StudentInfo builderStudentInfoByUI(StudentInfo student)
			throws ParseException {
		student.setName(this.getJTName().getText());
		student.setNumber(this.getJTNumber().getText());
		student.setSex((String) this.getJCSex().getSelectedItem());
		student.setPhyle(this.getJTMingZhu().getText());

		student.setBirthday(DateUtil.parseYYYYMMDD(this.getJTBirthday()
				.getText()));
		student.setAddres(this.getJTAddress().getText());
		student.setFatherName(this.getJTFatherName().getText());
		student.setMotherName(this.getJTMotherName().getText());
		student.setFatherPhone(this.getJTFatherPhone().getText());
		student.setMotherPhone(this.getJTMotherPhone().getText());
		student.setZip(this.getJTZip().getText());
		// student.getClassInfo().getName()

		// this.getJTBanJi().setText();
		student.setNativePlace(this.getJTJiGuan().getText());
		student.setZhuangYe(this.getJTZhuangYe().getText());
		student.setClassName(this.getJTBanJi().getText());

		return student;
	}

	/**
	 * This method initializes jCKeChengName
	 *
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJCKeChengName() {
		if (jCKeChengName == null) {
			jCKeChengName = new JComboBox();
			jCKeChengName.setBounds(new Rectangle(61, 154, 60, 18));
			jCKeChengName.setEnabled(false);
			jCKeChengName.addItemListener(this);
		}
		return jCKeChengName;
	}

	/**
	 * This method initializes jTBanJi
	 *
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTBanJi() {
		if (jTBanJi == null) {
			jTBanJi = new JTextField();
			jTBanJi.setBounds(new Rectangle(330, 167, 165, 18));
			jTBanJi.setEnabled(false);
		}
		return jTBanJi;
	}

	private void addChengJi() {
		ObjectContainer oc = DataBaseConnector.getDb();
		try {
			KeMuChengJi kmcj = new KeMuChengJi();
			kmcj.setChengJi(Float.parseFloat(this.getJTChengJi().getText()));
			kmcj.setCi(this.ci);
			kmcj.setRemark(this.getJTRemark().getText());
			kmcj.setStuInfo(this.stuInfo);
			oc.set(kmcj);
			oc.commit();
			oc.close();
		} catch (Exception e) {
			oc.rollback();
			oc.close();
		}
	}

	private void deleteChengJi() {
		ObjectContainer oc = DataBaseConnector.getDb();
		try {
			oc.delete(this.keMuChengJi);
			oc.commit();
			oc.close();
		}  catch (Exception e) {
			oc.rollback();
			oc.close();
		}
	}

	private void modifyChengJi() {
		ObjectContainer oc = DataBaseConnector.getDb();
		try {
			this.keMuChengJi.setChengJi(Float.parseFloat(this.getJTChengJi().getText()));
			keMuChengJi.setRemark(this.getJTRemark().getText());
			oc.set(keMuChengJi);
			oc.commit();
			oc.close();
		}  catch (Exception e) {
			oc.rollback();
			oc.close();
		}
	}

	private void initKeChengCommboxItem() {
		List<CoursesInfo> list = this.otherUtil.getCourseInfos();
		for (CoursesInfo ci : list) {
			this.getJCKeChengName().addItem(ci.getName());
			this.getJTKeChengNum().setText(ci.getNumber());
		}
	}

	public void itemStateChanged(ItemEvent arg0) {
		Object source = arg0.getSource();
		if (source == this.getJCKeChengName()) {
			this.ci = this.otherUtil.getCoursesInfo((String) this
					.getJCKeChengName().getSelectedItem());
			this.getJTKeChengNum().setText(ci.getNumber());
		}
	}

	public void valueChanged(ListSelectionEvent e) {
		ListSelectionModel lsm = (ListSelectionModel) e.getSource();
		int i = lsm.getMinSelectionIndex();
		if (i >= 0) {
			String num = (String) this.getJTable().getModel().getValueAt(i, 1);
			List<KeMuChengJi> list = this.otherUtil
					.getKeMuChengJis(this.stuInfo);
			for (KeMuChengJi kmcj : list) {
				if (kmcj.getCi().getNumber().trim().equals(num.trim())) {
					this.keMuChengJi = kmcj;

					break;
				}
			}
			if (keMuChengJi != null) {
				this.getJCKeChengName().setSelectedItem(
						keMuChengJi.getCi().getName());

				this.getJTChengJi().setText(
						String.valueOf(keMuChengJi.getChengJi()));
				this.getJTKeChengNum().setText(keMuChengJi.getCi().getNumber());
				this.getJTRemark().setText(keMuChengJi.getRemark());

			}
		}
	}

	/**
	 * This method initializes jBCalendar
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJBCalendar() {
		if (jBCalendar == null) {
			jBCalendar = new JButton();
			jBCalendar.setBounds(new Rectangle(205, 76, 21, 18));
			jBCalendar.setText(".");
			jBCalendar.setActionCommand(CALENDAL);
			jBCalendar.addActionListener(this);
		}

		return jBCalendar;
	}

	public static void main(String[] args) {
		JFrame jf = new JFrame();
		jf.add(new StudentInfoPanel());
		jf.show();
		jf.setSize(500, 400);
	}

	public void valueChanged(DateSelectionEvent arg0) {


	}
} // @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -