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

📄 updatestuinfo.java

📁 用java2核心类库写的一个学生课程管理系统
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;


public class UpdateStuInfo extends JFrame
{
	private JPanel content;
	private JLabel stuIDLabel;
	private JTextField stuIDText;
	private JButton okButton;
	private JButton cancleButton;

    private static final UpdateStuInfo UpdateStu = new UpdateStuInfo();
 
    public static UpdateStuInfo singleUpdateStuInfo()
	{
		return UpdateStu;
	}

    private UpdateStuInfo()
    {
    	initUpdateStuInfo();
  
    	ClickActionListener  cal = new ClickActionListener();
    	okButton.addActionListener(cal);
    	cancleButton.addActionListener(cal);
    }
	private void initUpdateStuInfo()
    {
    	this.setTitle("修改学生信息");
    	
    	
    	content = new JPanel();
    	stuIDLabel = new JLabel("请输入修改学生的学号:   ");
    	stuIDText= new JTextField(10);

    	okButton = new JButton("确定");
    	cancleButton=new  JButton("清除");
        content.add(stuIDLabel);
    	content.add(stuIDText);
        content.add(okButton );
    	content.add(cancleButton );
    
    	content.setLayout(new FlowLayout());
    	this.add(content);
    	this.setSize(300,300);	
   }

    class ClickActionListener implements ActionListener  
    {    
	    public void actionPerformed(ActionEvent e)
	    {
	    	String stuID = null;
	    	if (e.getActionCommand() == "确定")
	    	{
	    		stuID = stuIDText.getText();
	    		if (stuID!=null)
	    		{
	    		    String sqlselect = null;
	    		    sqlselect = "select * from 学生信息 where 学号 = " + "\'" + stuID +"\'";
     	
	    		    System.out.println("sqlselect1  = "  + sqlselect);
	    		    //SMISDB selectStuInfoDB = new SMISDB();
	    		    UpdateStuRecord f = new UpdateStuRecord(sqlselect);
	    		    //selectStuInfoDB.getTable(sqlselect, f);
	    		    //f.setUpdateDBPanel();

	    		    //JFrame f = new JFrame();

	    		    //JButton confirmUpdateDBBtn = new JButton("ok");
	    		    //confirmUpdateDBBtn.setSize(10,10);
	    		    //JPanel updateDBPanel = new JPanel();
	    		    //JButton cancleUpdateDBBtn = new JButton("cancle");
	    		    //cancleUpdateDBBtn.setSize(10,10);
	    		    //selectStuInfoDB.getTable(sqlselect, f);
	    		    //updateDBPanel.add(confirmUpdateDBBtn);
	    		    //updateDBPanel.add(cancleUpdateDBBtn);
	    		    
	    		    //f.add(updateDBPanel, BorderLayout.SOUTH);
	    		    
	    		    
    		
	    		    //UpdateStuFrame.singleUpdateStuFrame();
	    		}
	    	}
	    	else if (e.getActionCommand() == "清除")
	    	{
	    		stuIDText.setText("");
	    	}
	    }
    }    
}

class UpdateStuRecord extends JFrame
{
	final private int CNT = 8;
	private String  sqlStr;
	private SMISDB selectStuInfoDB;
	
	private Vector row = new Vector();
	
	public UpdateStuRecord( String str)
	{
		sqlStr = str;
		selectStuInfoDB = new SMISDB();
		int cnt = selectStuInfoDB.getTable(sqlStr, this,false);
		if ( cnt >0 )
		{
	    	row = selectStuInfoDB.getVectorData();
	    	if ( row == null)
	    	{
		    	// error
			    System.out.println("-------------------------------------error: vector is null");
	   	    }
	    	else // get vector data is ok
		    {
		    	System.out.println("-------------------------------------ok: get vector data is ok");
			    setUpdateDBPanel();
		    }
		}
		else
		{
			//no record or have error 
			System.out.println("----------------------------------no record or have error ");
		}
	}
	
	public void setUpdateDBPanel()
	{
	    final String stuInfoLableText[] = {
		    "学号:   ",
		    "姓名:    ",
		    "性别:    ",
    	    "年龄:    ",
    	    "政治面貌:",
        	"专业:    ",
       	    "民族:    ",
    	    "籍贯:    "
    	};

    	JLabel stuInfoLabel[] = new JLabel[CNT] ;
    	JTextField stuInfoText[] = new JTextField[CNT] ;
	    JPanel content[] = new JPanel[CNT] ;

		JButton confirmUpdateDBBtn;
	    JButton cancleUpdateDBBtn;
	    JPanel  updateDBPanel;
	
	
	    //初始化窗口
	    this.setTitle("修改学生信息");

    	for (int i=0;i<CNT;i++)
    	{
    		stuInfoLabel[i] = new JLabel(stuInfoLableText[i] );
    		stuInfoText[i] = new JTextField(10);
    		content[i] = new JPanel();
    		content[i].add(stuInfoLabel[i]);
    		content[i].add(stuInfoText[i]);
    		this.add(content[i]);
    	}
    	
    	confirmUpdateDBBtn = new JButton("修改");
		cancleUpdateDBBtn = new JButton("取消");
		updateDBPanel = new JPanel();
		
		updateDBPanel.add(confirmUpdateDBBtn);
		updateDBPanel.add(cancleUpdateDBBtn);
		
		this.add(updateDBPanel);

    	this.setLayout(new FlowLayout());
    	this.setSize(380,420);
    	this.setVisible(true);
    	System.out.println("------------------setVisible ok----------------");
    	//initUpdateStuFrame();
    	
    	//为button注册监听器
    	ClickActionListener  cal = new ClickActionListener();
    	confirmUpdateDBBtn.addActionListener(cal);
    	cancleUpdateDBBtn.addActionListener(cal);
	}
	
/*	private void initUpdateStuFrame()
    {
    	this.setTitle("修改学生信息");

    	for (int i=0;i<CNT;i++)
    	{
    		stuInfoLabel[i] = new JLabel(stuInfoLableText[i] );
    		stuInfoText[i] = new JTextField(10);
    		content[i] = new JPanel();
    		content[i].add(stuInfoLabel[i]);
    		content[i].add(stuInfoText[i]);
    		this.add(content[i]);
    	}
    	
    	confirmUpdateDBBtn = new JButton("修改");
		cancleUpdateDBBtn = new JButton("取消");
		updateDBPanel = new JPanel();
		
		updateDBPanel.add(confirmUpdateDBBtn);
		updateDBPanel.add(cancleUpdateDBBtn);
		
		this.add(updateDBPanel);

    	this.setLayout(new FlowLayout());
    	this.setSize(380,420);
		
    }
*/
    class ClickActionListener implements ActionListener
    {
    	public void actionPerformed(ActionEvent e)
	    {
	    	if (e.getActionCommand() == "修改")
	    	{
	    	
	    	    	System.out.println("修改成功");

	    	}
	    	if (e.getActionCommand() == "取消")
	    	{
	    		System.out.println("update failure");
	    	}
        } 
   }
}

⌨️ 快捷键说明

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