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

📄 delete.java

📁 成绩分析器 可以用来实现一些相关功能
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Delete extends JPanel implements ActionListener{ 
	Hashtable baseInformation=null;                           
  	JTextField number,name,math,english,computer;
  	JButton delete;
  	FileInputStream inOne=null;
  	ObjectInputStream inTwo=null;
  	FileOutputStream outOne=null;
  	ObjectOutputStream outTwo=null;
  	File file=null;                                           
  	public Delete(File file){
   		this.file=file;
   		number=new JTextField(10);
   		delete=new JButton("删除");
   		number.addActionListener(this);
   		delete.addActionListener(this);
   		name=new JTextField(10);
   		name.setEditable(false);
   		math=new JTextField(10);
   		math.setEditable(false);
   		english=new JTextField(10);
   		english.setEditable(false);
   		computer=new JTextField(10);
   		computer.setEditable(false);
   		Box box1=Box.createHorizontalBox();              
   		box1.add(new JLabel("输入要删除的学号:",JLabel.CENTER));
   		box1.add(number);
   		box1.add(delete);
	   	Box box2=Box.createHorizontalBox();              
	   	box2.add(new JLabel("姓名:",JLabel.CENTER));
	   	box2.add(name);
	   	Box box3=Box.createHorizontalBox();              
	   	box3.add(new JLabel("在下面是各门课程成绩(0-100的整数)",JLabel.CENTER));
	   	Box box4=Box.createHorizontalBox();              
	   	box4.add(new JLabel("数学成绩:",JLabel.CENTER));
	   	box4.add(math);
	   	Box box5=Box.createHorizontalBox();              
	   	box5.add(new JLabel("英语成绩:",JLabel.CENTER));
	   	box5.add(english);
	   	Box box6=Box.createHorizontalBox();              
	   	box6.add(new JLabel("电脑成绩:",JLabel.CENTER));
	   	box6.add(computer);
	   	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);
	   	validate();
  	}
 	public void actionPerformed(ActionEvent e){
    	if(e.getSource()==delete||e.getSource()==number){
        	String stunumber="";
        	stunumber=number.getText();
        	if(stunumber.length()>0){
            	try{
                	inOne=new FileInputStream(file);
                    inTwo=new ObjectInputStream(inOne);
                    baseInformation=(Hashtable)inTwo.readObject();
                    inOne.close();
                    inTwo.close();
                }
               	catch(Exception ee){
                }
              	if(baseInformation.containsKey(stunumber)){
                	Student stu=(Student)baseInformation.get(stunumber);
                   	name.setText(stu.getName());
                   	math.setText(stu.getMath());
                   	english.setText(stu.getEnglish());
                   	computer.setText(stu.getComputer());
                  	String m="确定要删除该学号及全部信息吗?";
                  	int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                  	if(ok==JOptionPane.YES_OPTION){
                    	baseInformation.remove(stunumber);
                       	try{
                          	outOne=new FileOutputStream(file);
                          	outTwo=new ObjectOutputStream(outOne);
                          	outTwo.writeObject(baseInformation);
                          	outTwo.close();
                          	outOne.close();
                          	number.setText(null);
                          	name.setText(null);                                
                          	math.setText(null);
                          	english.setText(null);
                          	computer.setText(null);
                        }
                       	catch(Exception ee){ 
                         	System.out.println(ee);
                        }	
                    }
                   	else if(ok==JOptionPane.NO_OPTION){
                    	number.setText(null);
                        name.setText(null);
                        math.setText(null);
                        english.setText(null);
                        computer.setText(null);
                    }
                }
              	else{ 
                  	String warning="该学号不存在!";
                  	JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
               	}
            }
        	else{ 
            	String warning="必须要输入学号!";
              	JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
            }
      	} 
  	}
}

⌨️ 快捷键说明

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