📄 inquestgrade.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
/**
* @author tsiudongyang
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class InquestGrade extends JDialog implements ActionListener
{
Hashtable 基本成绩表=null;
JTextField 学号,语文,英语,数学;
JButton 退出;
JButton 查询;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
File file=null;
public InquestGrade(JFrame f,File file)
{
super(f,"学生成绩查询",false);
this.file=file;
查询=new JButton("查询");
查询.addActionListener(this);
退出=new JButton("退出");
退出.addActionListener(this);
学号=new JTextField(10);
学号.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(数学);
//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);
Container con=getContentPane();
con.add(pCenter,BorderLayout.CENTER);
con.validate();
JPanel pSouth=new JPanel();
pSouth.add(退出);
add(pSouth,BorderLayout.SOUTH);
validate();
setVisible(false);
setBounds(100,200,360,270);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
}////////////
public void actionPerformed(ActionEvent e)
{
语文.setText(null);//语文,英语,数学
数学.setText(null);
英语.setText(null);
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.getEnglish());
数学.setText(stu.getMath());
}
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 + -