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

📄 deletegrade.java

📁 本软件很好的解决了学生信息管理的功能
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.io.*;
import java.util.*;
public class DeleteGrade extends JDialog implements ActionListener
{ 
  Hashtable 基本成绩表=null;                           
  JTextField 学号,语文,英语,数学;
  JButton 删除;
  JButton 退出;
  FileInputStream inOne=null;
  ObjectInputStream inTwo=null;
  FileOutputStream outOne=null;
  ObjectOutputStream outTwo=null;
  File file=null;                                           
  public DeleteGrade(JFrame f,File file)
  {
   super(f,"学生成绩删除",false);
   this.file=file;
 
   学号=new JTextField(10); 
   学号.addActionListener(this);////
   
   删除=new JButton("删除");
   删除.addActionListener(this);
   
   退出=new JButton("退出");
   退出.addActionListener(this);
   
   语文=new JTextField(10);
   语文.setEditable(false);
   
   数学=new JTextField(10);
   数学.setEditable(false);
   
   英语=new JTextField(10);
   英语.setEditable(false);
   

   
   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(数学);
   
   Box box4=Box.createHorizontalBox();              
   box4.add(new JLabel("英语:",JLabel.CENTER));
   box4.add(英语);
   
   Box boxH=Box.createVerticalBox();              
   boxH.add(box1);
   boxH.add(box2);
   boxH.add(box3);
   boxH.add(box4);
   boxH.add(Box.createVerticalGlue());  
   
   JPanel pCenter=new JPanel();
   pCenter.add(boxH);
   setLayout(new BorderLayout());
   add(pCenter,BorderLayout.CENTER);
   setBounds(100,200,360,270);
   validate();
   JPanel pSouth=new JPanel();
   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);
                    基本成绩表=(Hashtable)inTwo.readObject();
                    inOne.close();
                    inTwo.close();
                  }
               catch(Exception ee)
                   {
                   }
              if(基本成绩表.containsKey(number))          
                 {
                   StudentG stu=(StudentG)基本成绩表.get(number);
                   语文.setText(stu.getChinese());
                   数学.setText(stu.getMath());
                   英语.setText(stu.getEnglish());
                   
                  String m="确定要删除该学号及全部信息吗?";
                  int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
                                                 JOptionPane.QUESTION_MESSAGE);
                  if(ok==JOptionPane.YES_OPTION)
                     {
                  	基本成绩表.remove(number);
                       try
                        {
                          outOne=new FileOutputStream(file);
                          outTwo=new ObjectOutputStream(outOne);
                          outTwo.writeObject(基本成绩表);
                          outTwo.close();
                          outOne.close();
                          学号.setText(null);
                          语文.setText(null);                                
                          数学.setText(null);
                          英语.setText(null);
                          }
                       catch(Exception ee)
                        { 
                         System.out.println(ee);
                        }
                     }
                   else if(ok==JOptionPane.NO_OPTION)
                     {
                        学号.setText(null);
                        语文.setText(null);                                
                        数学.setText(null);
                        英语.setText(null);
                     }
                 }
              else
                 { 
                  String warning="该学号不存在!";
                  JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
                 }
            }
        else
            { 
              String warning="必须要输入学号!";
              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
            }
      }
    if(e.getSource()==退出)
    {
    	this.dispose();
    }
  }
}

⌨️ 快捷键说明

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