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

📄 modifysituation.java

📁 该源程序是自做的一个简单的学籍管理系统
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;

public class ModifySituation extends JPanel implements ActionListener
{ 
                          
  JTextField 学号,姓名,专业,年级,出生;                 
  JRadioButton 男,女;
  ButtonGroup group=null;
  JButton 开始修改,录入修改,重置;
                                          
  public ModifySituation()
  {
   
   学号=new JTextField(10);
   姓名=new JTextField(10);                                
   专业=new JTextField(10);
   年级=new JTextField(10);
   出生=new JTextField(10);
   group=new ButtonGroup();
   男=new JRadioButton("男",true);
   女=new JRadioButton("女",false);
   group.add(男);
   group.add(女);
   开始修改=new JButton("开始修改");
   录入修改=new JButton("录入修改");
   录入修改.setEnabled(false);
   重置=new JButton("重置");
   学号.addActionListener(this);
   开始修改.addActionListener(this);
   录入修改.addActionListener(this);
   重置.addActionListener(this);
   Box box1=Box.createHorizontalBox();              
   box1.add(new JLabel("输入要修改信息的学号:",JLabel.CENTER));
   box1.add(学号);
   box1.add(开始修改);
   Box box2=Box.createHorizontalBox();              
   box2.add(new JLabel("(新)姓名:",JLabel.CENTER));
   box2.add(姓名);
   Box box3=Box.createHorizontalBox();              
   box3.add(new JLabel("(新)性别:",JLabel.CENTER));
   box3.add(男);
   box3.add(女);
   Box box4=Box.createHorizontalBox();              
   box4.add(new JLabel("(新)专业:",JLabel.CENTER));
   box4.add(专业);
   Box box5=Box.createHorizontalBox();              
   box5.add(new JLabel("(新)年级:",JLabel.CENTER));
   box5.add(年级);
   Box box6=Box.createHorizontalBox();              
   box6.add(new JLabel("(新)出生:",JLabel.CENTER));
   box6.add(出生);
   Box boxH=Box.createVerticalBox();              
   boxH.add(box1);
   boxH.add(box2);
   boxH.add(box3);
   boxH.add(box4);
   boxH.add(box5);
   boxH.add(box6);
   boxH.add(Box.createVerticalGlue());           
   JPanel pCenter=new JPanel();
   pCenter.add(boxH);
   setLayout(new BorderLayout());
   add(pCenter,BorderLayout.CENTER);
   JPanel pSouth=new JPanel();
   pSouth.add(录入修改);
   pSouth.add(重置);
   add(pSouth,BorderLayout.SOUTH);
   validate();
  }
 public void actionPerformed(ActionEvent e)
 { String mu="";
   if(e.getSource()==开始修改||e.getSource()==学号)
      {
        String number="",Grade1="",Disciping1="",Borth1="",Name1="",Sex1="";
        number=学号.getText().trim(); 
         if(number.length()>0)
            {
               Connection con;
               Statement sql; 
               ResultSet rs,rs1;
        	  try{  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
     	      catch(ClassNotFoundException e2)
	              {System.out.print("找不到驱动");}
     	    try { con=DriverManager.getConnection("jdbc:odbc:sun","","");
                   sql=con.createStatement();
                   rs=sql.executeQuery("SELECT * FROM student");
                  
            	 while(rs.next())
            	   { 
            	    mu=rs.getString(1);
            	    if(mu.equals(number))
            	     { Name1=rs.getString(2);
     	               Sex1=rs.getString(3);
      	               Disciping1=rs.getString(4);
      	               Grade1=rs.getString(5);
      	               Borth1=rs.getString(6);
            	    	break;
            	    }
            	    else continue;
                   }
                if(mu.equals(number))          
                  { 
                     录入修改.setEnabled(true);
                     姓名.setText(Name1);
                     专业.setText(Disciping1);
                     年级.setText(Grade1);
                     出生.setText(Borth1); 
                    if(Sex1.equals("男"))
                      { 男.setSelected(true); }
                    else
                      {  女.setSelected(true);  }
                   } 
                else
                  { 
                   录入修改.setEnabled(false);   
                    String warning="该学号不存在!";
                    JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
                    学号.setText(null);
                    姓名.setText(null);                                
                    专业.setText(null);
                    年级.setText(null);
                    出生.setText(null);
                   } con.close();
        	  }
           catch (SQLException ww){System.out.print(ww);}
       	     } 
        else
            { 
              录入修改.setEnabled(false); 
              
              String warning="必须要输入学号!";
              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
              学号.setText(null);
              姓名.setText(null);                                
              专业.setText(null);
              年级.setText(null);
              出生.setText(null);
            }
        mu=null;
       	 }
  else if(e.getSource()==录入修改)
      { 
        String number="",nu="";
        number=学号.getText();
        if(number.length()>0)
           {  Connection con;
              Statement sql; 
              ResultSet rs;
     	     try{  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
  	         catch(ClassNotFoundException e2)
	              {System.out.print("找不到驱动");}
  	    try { con=DriverManager.getConnection("jdbc:odbc:sun","","");
              sql=con.createStatement(); System.out.print("hh");
              rs=sql.executeQuery("SELECT 学号 FROM student WHERE 学号 = 'number' ");
         	  while(rs.next())
         	    {  nu=rs.getString("学号");  }
              if(nu!=null)          
                 {
                  String question="该生基本信息已存在,您想修改他(她)的基本信息吗?";
                  JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE);
                  String m="基本信息将被修改!";
                  int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                  if(ok==JOptionPane.YES_OPTION)
                    {
                      String name=姓名.getText();
                      String discipling=专业.getText();
                      String grade=年级.getText();
                      String borth=出生.getText();
                      String sex=null;
                        if(男.isSelected())
                           {  sex=男.getText(); }
                        else
                           {  sex=女.getText(); }
                       try
                          {    String temp="UPDATE student SET 姓名="+"'"+name+"'"+",性别="+"'"+sex+"'"+",专业="+"'"+discipling+"'"+",年级="+"'"+grade+"'"+",出生年月="+"'"+borth+"'"+" WHERE 学号="+"'"+number+"'"+"";
                      	       sql.executeUpdate(temp); 
                               学号.setText(null);
                               姓名.setText(null);                                
                               专业.setText(null);
                               年级.setText(null);
                               出生.setText(null);
                         }
                    catch(Exception ee)
                        {  System.out.println(ee); }
                     录入修改.setEnabled(false); 
                     } 
                  else 
                    {   录入修改.setEnabled(true); }
                 }      
              else
               {
                 String warning="该学号没有基本信息,不能修改!";
                 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
                 录入修改.setEnabled(false); 
               } con.close();
          } 
      catch (SQLException iq){}
     	   }
        else
           {
              String warning="必须要输入学号!";
              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
              录入修改.setEnabled(false);
           } 
        
       }
     	     
          
   if(e.getSource()==重置)
      {  学号.setText(null);
        姓名.setText(null);
        专业.setText(null);
        年级.setText(null);
        出生.setText(null);
      }
   }
}

⌨️ 快捷键说明

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