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

📄 inquest.java

📁 成绩分析器 可以用来实现一些相关功能
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Inquest extends JDialog implements ActionListener{ 
	Hashtable baseInformation=null;                           
  	JTextField number,name,math,english,computer;                 
  	JButton search;
  	FileInputStream inOne=null;
  	ObjectInputStream inTwo=null;
  	File file=null;                                           
  	public Inquest(JFrame f,File file){
   		super(f,"查询对话框",false);                           
   		this.file=file;
   		number=new JTextField(10);
   		search=new JButton("查询");
   		number.addActionListener(this);
   		search.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(search);
   		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);
   		Container con=getContentPane();
   		con.add(pCenter,BorderLayout.CENTER);
   		con.validate();
   		setVisible(false);
   		setBounds(100,200,360,270);
   		addWindowListener(new WindowAdapter(){
   			public void windowClosing(WindowEvent e){
            	setVisible(false);
      	    }
        });
  	}
 	public void actionPerformed(ActionEvent e){    
    	name.setText(null);
    	math.setText(null);
     	english.setText(null);
     	computer.setText(null);
     	if(e.getSource()==search||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);//取出学号为stunumber的学生的信息赋给stu对象
                	name.setText(stu.getName());
                	math.setText(stu.getMath());
                	english.setText(stu.getEnglish());
                	computer.setText(stu.getComputer()); 
            	}
            	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 + -