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

📄 updatestudent.java

📁 accp s1毕业项目 考试管理系统
💻 JAVA
字号:
package com.exam.ui.banzhuren;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.exam.db.bean.Student;
import com.exam.db.dao.StudentDao;
import com.exam.ui.SuperFrame;
import com.exam.ui.utils.NumberLenghtLimitedDmt;

public class UpdateStudent extends SuperFrame {
	private static final long serialVersionUID = 1L;
	public UpdateStudent(String stuID, String stuName, String stuSex,
			int stuAge, String stuBirthday, String stuCardID, String StuNation,
			String StuPhone, String StuAddr, int StuState, String BanJiID,
			String Remark) {
		try {
			init(stuID, stuName, stuSex, stuAge, stuBirthday, stuCardID,
					StuNation, StuPhone, StuAddr, StuState, BanJiID, Remark);
			this.setVisible(true);
			this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void init(String stuID, String stuName, String stuSex, int stuAge,
			String stuBirthday, String stuCardID, String StuNation,
			String StuPhone, String StuAddr, int StuState, String BanJiID,
			String Remark) {
		this.setTitle("修改学生信息");
		this.setSize(600, 400);
		this.setResizable(false);
		this.setCenter();

		// 取底层面板
		Container ct = this.getContentPane();
		ct.setLayout(null);

		JLabel lblStuName = new JLabel("姓        名");
		lblStuName.setBounds(70, 30, 70, 20);
		ct.add(lblStuName);

		final JTextField txtStuName = new JTextField();
		txtStuName.setBounds(140, 30, 130, 20);
		txtStuName.setText(stuName);
		ct.add(txtStuName);

		JLabel lblStuBanji = new JLabel("所属班级");
		lblStuBanji.setBounds(320, 70, 70, 20);
		ct.add(lblStuBanji);

		final JTextField txtStuBanji = new JTextField();
		txtStuBanji.setBounds(390, 70, 130, 20);
		txtStuBanji.setText(BanJiID);
		ct.add(txtStuBanji);

		JLabel lblStuCardID = new JLabel("身份证号");
		lblStuCardID.setBounds(70, 70, 70, 20);
		ct.add(lblStuCardID);

		final JTextField txtStuCardID = new JTextField();
		txtStuCardID.setBounds(140, 70, 130, 20);
		txtStuCardID.setEditable(false);
		txtStuCardID.setText(stuCardID);
		ct.add(txtStuCardID);

		JLabel lblStuSex = new JLabel("性        别");
		lblStuSex.setBounds(320, 30, 70, 20);
		ct.add(lblStuSex);

		final JTextField txtSex = new JTextField();
		txtSex.setBounds(390, 30, 130, 20);
		txtSex.setText(stuSex);
		ct.add(txtSex);

		JLabel lblStuDate = new JLabel("出生日期");
		lblStuDate.setBounds(70, 150, 70, 20);
		ct.add(lblStuDate);

		final JTextField txtStuBirthday = new JTextField();
		txtStuBirthday.setEditable(false);
		txtStuBirthday.setBounds(140, 150, 130, 20);
		txtStuBirthday.setText(stuBirthday);
		ct.add(txtStuBirthday);

		JLabel lblStuID = new JLabel("学        号");
		lblStuID.setBounds(320, 110, 70, 20);
		ct.add(lblStuID);

		final JTextField txtStuID = new JTextField();
		txtStuID.setBounds(390, 110, 130, 20);
		txtStuID.setEditable(false);
		txtStuID.setText(stuID);
		ct.add(txtStuID);

		JLabel lblStuPhone = new JLabel("电话号码");
		lblStuPhone.setBounds(70, 110, 80, 20);
		ct.add(lblStuPhone);

		final JTextField txtStuPhone = new JTextField();
		txtStuPhone.setBounds(140, 110, 130, 20);
		txtStuPhone.setText(StuPhone);
		txtStuPhone.setDocument(new NumberLenghtLimitedDmt(12));
		ct.add(txtStuPhone);

		JLabel lblStuAge = new JLabel("年        龄");
		lblStuAge.setBounds(320, 150, 80, 20);
		ct.add(lblStuAge);

		final JTextField txtStuAge = new JTextField();
		txtStuAge.setBounds(390, 150, 130, 20);
		txtStuAge.setEditable(false);
		txtStuAge.setText(stuAge + "");
		ct.add(txtStuAge);

		JLabel lblStuNation = new JLabel("民        族");
		lblStuNation.setBounds(70, 190, 70, 20);
		ct.add(lblStuNation);

		final JTextField txtNation = new JTextField();
		txtNation.setBounds(140, 190, 130, 20);
		txtNation.setText(StuNation);
		ct.add(txtNation);

		final JLabel lblStuState = new JLabel("当前状态");
		lblStuState.setBounds(320, 190, 70, 20);
		ct.add(lblStuState);

		final JComboBox cboState = new JComboBox();
		cboState.setBounds(390, 190, 130, 20);
		cboState.addItem("在读");
		cboState.addItem("休学");
		cboState.addItem("退学");
		cboState.addItem("毕业");
		cboState.setSelectedItem(StuState);
		ct.add(cboState);

		JLabel lblStuAddr = new JLabel("家庭住址");
		lblStuAddr.setBounds(70, 245, 70, 20);
		ct.add(lblStuAddr);

		final JTextArea txaStuAddr = new JTextArea();
		txaStuAddr.setLineWrap(true);
		txaStuAddr.setText(StuAddr);
		JScrollPane scpAddr = new JScrollPane(txaStuAddr);
		scpAddr.setBounds(140, 230, 130, 50);
		ct.add(scpAddr);

		JLabel lblStuRemark = new JLabel("备         注");
		lblStuRemark.setBounds(320, 245, 70, 20);
		ct.add(lblStuRemark);

		// 多行文本框加滚动条
		final JTextArea txaStuRemark = new JTextArea();
		txaStuRemark.setLineWrap(true);
		txaStuRemark.setText(Remark);
		JScrollPane scpRemark = new JScrollPane(txaStuRemark);
		scpRemark.setBounds(390, 230, 130, 50);
		ct.add(scpRemark);

		JButton btnSava = new JButton("保      存");
		btnSava.setBounds(180, 320, 100, 25);
		ct.add(btnSava);

		JButton btnReset = new JButton("取      消");
		btnReset.setBounds(320, 320, 100, 25);
		ct.add(btnReset);

		btnSava.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String stuNewName = txtStuName.getText();
				if (stuNewName.equals("")) {
					JOptionPane.showMessageDialog(null, "请输入姓名!");
					txtStuName.requestFocus();
				}
				String stuNewID = txtStuID.getText();
				String stuNewSex = txtSex.getText();
				String stuNewAge = txtStuAge.getText();
				String stuNewBirthday = txtStuBirthday.getText();
				String stuNewCardID = txtStuCardID.getText();
				String stuNewNation = txtNation.getText();
				String stuNewPhone = txtStuPhone.getText();
				String stuNewAddr = txaStuAddr.getText();
				if (stuNewAddr.equals("")) {
					JOptionPane.showMessageDialog(null, "请输入家庭住址!");
					txtStuName.requestFocus();
				}
				int stuNewState = 0;
				stuNewState = cboState.getSelectedIndex();
				String stuNewBanJiID = txtStuBanji.getText();
				if (stuNewBanJiID.equals("")) {
					JOptionPane.showMessageDialog(null, "请输入所属班级!");
					txtStuName.requestFocus();
				}
				String stuNewRemark = txaStuRemark.getText();
				// 将输入的学生信息添加到学生对象中
				Student student = new Student();
				student.setStuName(stuNewName);
				student.setStuID(stuNewID);
				student.setStuSex(stuNewSex);
				student.setStuAge(Integer.parseInt(stuNewAge));
				student.setStuBirthday(stuNewBirthday);
				student.setStuCardID(stuNewCardID);
				student.setStuNation(stuNewNation);
				student.setStuPhone(stuNewPhone);
				student.setStuAddr(stuNewAddr);
				student.setStuState(stuNewState);
				student.setBanJiID(stuNewBanJiID);
				student.setRemark(stuNewRemark);
				// 接收保存的条数
				int result = new StudentDao().updateStudentByID(student);
				if (result == 1) {
					JOptionPane.showMessageDialog(null, "保存成功!");
					dispose();
				} else {
					JOptionPane.showMessageDialog(null, "保存失败!");
					return;
				}

			}
		});
		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int result = JOptionPane.showConfirmDialog(null, "你是否确定要取消?",
						"确定", JOptionPane.YES_NO_OPTION);
				if (result == 0) {
					System.exit(0);
				} else {
					setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}
			}
		});
		txtStuPhone.addFocusListener(new FocusListener() {

			public void focusGained(FocusEvent arg0) {}
			public void focusLost(FocusEvent arg0) {
	
				int stuPhonelength=txtStuPhone.getText().length();
				if( stuPhonelength==0||stuPhonelength==8||stuPhonelength==11 || stuPhonelength==12){
						
				}else{
					JOptionPane.showMessageDialog(null, "电话号码输入错误!");
					txtStuPhone.setText("");
					txtStuPhone.requestFocus();
				}
			}

		});
	}
}

⌨️ 快捷键说明

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