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

📄 cstumoddlg.java

📁 java版的windows界面的学生管理系统
💻 JAVA
字号:
package ui;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;
import javax.swing.border.LineBorder;

import value.*;
import main.*
;

/**
 * 
 * <p>标题:CStuModDlg</p>
 * <p>描述:修改学生信息窗体类</p>
 * <p>作者@author:陈新</p>
 * <p>公司:com.thinkbank.04024</p>
 * <p>版权:Copyrigth (c) 2005 </p>
 * <p>编写日期:2005-10-10</p>
 * <p>版本号@version 1.0.06.01 
 */
public class CStuModDlg extends javax.swing.JDialog implements ActionListener{
    
    private JButton jBtnCancel;//取消
    private JButton jBtnSubmit;//确定
    private JButton jStuSechBtn;//查询
    
    private JTextField jStuIDTxt;//查询学生号输入框
    
    
    private JLabel jStuNewId;//学生号,不可改
    private JTextField jStuNameTxt;//学生姓名
    private JComboBox jCmbStuSex;//学生性别
    private JComboBox jStuClass;//学生班级号 
   
    //只显示,不使用
    private JLabel jStuID;
    private JLabel jStuName;
    private JLabel jLabel1;
    private JLabel jStuSex;
    private JLabel jStuClsid;
    


    
    public CStuModDlg(JFrame frame) {
        super(frame);
        initGUI();
    }
    /**
     * 
     * <p>描述:窗体初始化方法</p>
     *
     *
     */
    private void initGUI() {
        try {
            this.setResizable(false);
            this.setTitle("修改学员信息");
            this.getContentPane().setLayout(null);
            {
                jStuID = new JLabel();
                this.getContentPane().add(jStuID);
                jStuID.setText("学员学号");
                jStuID.setLayout(null);
                jStuID.setBounds(86, 61, 85, 25);
            }
            {
                jStuNewId = new JLabel();
                this.getContentPane().add(jStuNewId);
                jStuNewId.setLayout(null);
                jStuNewId.setBounds(180, 61, 91, 23);
                jStuNewId.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
            }
            {
                jStuName = new JLabel();
                this.getContentPane().add(jStuName);
                jStuName.setText("学员姓名");
                jStuName.setLayout(null);
                jStuName.setBounds(85, 91, 85, 25);
            }
            {
                jStuNameTxt = new JTextField();
                this.getContentPane().add(jStuNameTxt);
                jStuNameTxt.setBounds(180, 93, 89, 23);
            }
            {
                jStuClsid = new JLabel();
                this.getContentPane().add(jStuClsid);
                jStuClsid.setText("所在班级");
                jStuClsid.setLayout(null);
                jStuClsid.setBounds(84, 121, 85, 25);
            }
            {
                jStuSex = new JLabel();
                this.getContentPane().add(jStuSex);
                jStuSex.setText("学员性别");
                jStuSex.setLayout(null);
                jStuSex.setBounds(85, 151, 85, 25);
            }
            {

                jStuClass = new JComboBox();
                this.getContentPane().add(jStuClass);
                this.cmbInit();
                jStuClass.setBounds(180, 121, 90, 20);
             
            }
            {
                ComboBoxModel jCmbStuSexModel = new DefaultComboBoxModel(
                    new String[] { "","男", "女" });
                jCmbStuSex = new JComboBox();
                this.getContentPane().add(jCmbStuSex);
                jCmbStuSex.setModel(jCmbStuSexModel);
                jCmbStuSex.setBounds(180, 150, 91, 20);
            }
            {
                jBtnSubmit = new JButton();
                this.getContentPane().add(jBtnSubmit);
                jBtnSubmit.setText("确定");
                jBtnSubmit.setBounds(108, 196, 60, 30);
                jBtnSubmit.addActionListener(this);
            }
            {
                jBtnCancel = new JButton();
                this.getContentPane().add(jBtnCancel);
                jBtnCancel.setText("取消");
                jBtnCancel.setBounds(187, 197, 60, 30);
                jBtnCancel.addActionListener(this);

            }
            {
                jLabel1 = new JLabel();
                this.getContentPane().add(jLabel1);
                jLabel1.setText("请输入要修改学员的学号");
                jLabel1.setBounds(20, 17, 154, 22);
            }
            {
                jStuIDTxt = new JTextField();
                this.getContentPane().add(jStuIDTxt);
                jStuIDTxt.setBounds(181, 18, 67, 22);
            }
            {
                jStuSechBtn = new JButton();
                this.getContentPane().add(jStuSechBtn);
                jStuSechBtn.setText("查找");
                jStuSechBtn.setBounds(273, 18, 84, 23);
                jStuSechBtn.addActionListener(this);
            }
            this.setSize(400, 300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   /**
    * 
    * <p>描述:班级下拉列表更新方法</p>
    *
    *
    */
    public void cmbInit(){
        CClsDAO clsDao = new CClsDAO();
        ArrayList clsList = clsDao.executeQuery();
        String[] strList = new String[clsList.size()+1];
        strList[0] = "";
        for(int j=0;j<clsList.size();j++){
            CClasses cls = new CClasses();
            cls = (CClasses) clsList.get(j);
            String clsID = cls.getStrClsId();
            strList[j+1] = clsID;
        }
        ComboBoxModel jStuClassModel = new DefaultComboBoxModel(strList);
        jStuClass.setModel(jStuClassModel);
    }
    /**
     * <p>描述:实现的监听器类的方法</p>
     */
    public void actionPerformed(ActionEvent evt){
        Object source = evt.getSource();
        if(source == jBtnCancel){
            this.setVisible(false);
        }
        else if(source == jStuSechBtn){
            if(jStuIDTxt.getText().equals("")){
                JOptionPane.showConfirmDialog(this,"请输入学生号","提示",
    					JOptionPane.CLOSED_OPTION,
    					JOptionPane.WARNING_MESSAGE);
            }
            else{
                CStuDAO stuDAO = new CStuDAO();
                ArrayList stuList = new ArrayList();
                String sql = "select *  from T_student where cStuId='" + jStuIDTxt.getText() + "'";
                stuList = stuDAO.executeQuery(sql);
                if(stuList!=null){
                    CStudents stu = (CStudents)stuList.get(0);
                    jStuNewId.setText(stu.getStrStuId());
                    jStuNameTxt.setText(stu.getStrStuName());
                    jStuClass.setSelectedItem(stu.getStrClsID());
                    jCmbStuSex.setSelectedItem(stu.getStrSex().trim());
                }
                else if(stuList == null){
     			    JOptionPane.showConfirmDialog(this,"不存在该学生号,请重新输入!","提示",
     			    JOptionPane.CLOSED_OPTION,JOptionPane.WARNING_MESSAGE);
     			}
            }

        }
        else if(source == jBtnSubmit){
            if(jStuNewId.getText().equals("")){
                JOptionPane.showConfirmDialog(this,"请先查找学生信息","提示",
    					JOptionPane.CLOSED_OPTION,
    					JOptionPane.WARNING_MESSAGE);
            }
            else{
                CStuDAO stuDAO = new CStuDAO();
                String sql = "update T_student set cName='" + jStuNameTxt.getText()
                			+ "',cSex='" + jCmbStuSex.getSelectedItem() + "',cClassId='"
                			+ jStuClass.getSelectedItem() + "'where cStuId='" + jStuNewId.getText()
                			+ "'";
                int i = stuDAO.executeUpdate(sql);
                if(i==1){
    	   	    	JOptionPane.showConfirmDialog(this,"修改成功!","提示",
    					JOptionPane.CLOSED_OPTION,
    					JOptionPane.WARNING_MESSAGE);
    	   	    	CMain.updateFrame();
    	   	    	jStuIDTxt.setText("");
    	   	    	jStuNewId.setText("  ");
    	   	    	jStuNameTxt.setText("");
    	   	    	jStuClass.setSelectedItem("");
    	   	    	jCmbStuSex.setSelectedItem("");
    	   	    	
                }

            }
 
        }
    }
}


⌨️ 快捷键说明

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