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

📄 modifysituation.java

📁 ——学生信息系统的设计与实现—— 以学生信息为背景
💻 JAVA
字号:
package student;


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;


public class ModifySituation extends JPanel implements ActionListener

{ 

  int i;                        

  JTextField 学号,姓名,专业,班级,年龄;                 

  JRadioButton 男,女;

  ButtonGroup group=null;

  JButton 开始修改,录入修改,重置;

  FileInputStream inOne=null;

  ObjectInputStream inTwo=null;

  FileOutputStream outOne=null;

  ObjectOutputStream outTwo=null;
  
  Lianbiao 基本信息[]=new Lianbiao[100];    

  File file=null;                                           

  public ModifySituation(File file)

  {
     for(i=0;i<100;i++)
     {    

          基本信息[i]=new Lianbiao();
     
     }
      
   this.file=file;

   学号=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();
   
      addWindowListener(new WindowAdapter()

                    { public void windowClosing(WindowEvent e)

                       {

                         setVisible(false);

                         }

                    });

  }

 public void actionPerformed(ActionEvent e)

 { 

   if(e.getSource()==开始修改||e.getSource()==学号)

      {

         String number="";

         number=学号.getText();

        

         if(number.length()>0)

            {

              try {

                    inOne=new FileInputStream(file);

                    inTwo=new ObjectInputStream(inOne);

                    基本信息=(Lianbiao[])inTwo.readObject();

                    inOne.close();

                    inTwo.close();

                  }

               catch(Exception ee)

                   {

                   }

              if(Lianbiao.cn(number))        

                 {

                   String warning="学号必须全为数字!";

                    

                   JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 }

                else if(Lianbiao.a(基本信息,number))                

                 {
                  

                   录入修改.setEnabled(true);
                   
                    Student 学生=new Student(); 

                  Lianbiao.lim(基本信息,学生,number);


                   姓名.setText(学生.getName());

                   专业.setText(学生.getDisciping());

                   班级.setText(学生.getJclass());

                   年龄.setText(学生.getAge()); 

                   if(学生.getSex().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);

 

                 }

            }

        else

            { 

              录入修改.setEnabled(false); 

              

              String warning="必须要输入学号!";

              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

              学号.setText(null);

              姓名.setText(null);                                

              专业.setText(null);

              班级.setText(null);

              年龄.setText(null);

            }

      } 

  else if(e.getSource()==录入修改)

      { 

           String number="";
        
            number=学号.getText();
            
             String name=姓名.getText();

               String discipling=专业.getText();

               String jclass=班级.getText();

              String age=年龄.getText();

             String sex=null;

             if(男.isSelected())

             {

                 sex=男.getText();

               }

               else

               {

               sex=女.getText();

               }    

        if(number.length()>0&&name.length()>0&&discipling.length()>0&&jclass.length()>0&&age.length()>0&&sex!=null)

           {

            try {

                 inOne=new FileInputStream(file);

                 inTwo=new ObjectInputStream(inOne);

                 基本信息=(Lianbiao[])inTwo.readObject();

                 inOne.close();

                 inTwo.close(); 

                }

            catch(Exception ee)

                {

                }

            if(!(Lianbiao.ca(number)||Lianbiao.cn(name)||Lianbiao.cd(discipling)||Lianbiao.cj(jclass)||Lianbiao.cg(age)))          

                {

                  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)

                    {



                     Student  学生=new Student();

                     学生.setNumber(number);

                     学生.setName(name);

                     学生.setDiscipling(discipling);

                     学生.setJclass(jclass);

                     学生.setAge(age);

                     学生.setSex(sex);

                     try

                      {

                       outOne=new FileOutputStream(file);

                       outTwo=new ObjectOutputStream(outOne);

                       Lianbiao.ti(基本信息,学生,number);

                       outTwo.writeObject(基本信息);

                       outTwo.close();

                       outOne.close();

                       学号.setText(null);

                       姓名.setText(null);                                

                       专业.setText(null);

                       班级.setText(null);

                       年龄.setText(null);

                      }

                     catch(Exception ee)

                      { 

                       System.out.println(ee);

                      }

                     录入修改.setEnabled(false); 

                   }

                 else if(ok==JOptionPane.NO_OPTION)

                   {

                     录入修改.setEnabled(true);

                   }

               }

             else

               {

                

                 String warning="基本信息有误,不能修改!";

                 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

                 录入修改.setEnabled(false); 

               }

           }

        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);

      }

  }

    private void addWindowListener(WindowAdapter windowAdapter) {
    }


}


⌨️ 快捷键说明

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