📄 insertgrade.java
字号:
/*
* Created on 2007-1-15
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
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 InsertGrade extends JDialog implements ActionListener
{
Hashtable 基本成绩表=null;
JTextField 学号,语文,英语,数学;
JButton 退出;
JButton 录入,重置;
StudentG 学生成=null;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
ObjectOutputStream outTwo=null;
File file=null;
public InsertGrade(JFrame f,File file)
{
super(f,"学生成绩录入",false);
this.file=file;
退出=new JButton("退出");
退出.addActionListener(this);
录入=new JButton("录入");
重置=new JButton("重置");
录入.addActionListener(this);
重置.addActionListener(this);
学号=new JTextField(10);
语文=new JTextField(10);
数学=new JTextField(10);
英语=new JTextField(10);
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(录入);
pSouth.add(重置);
pSouth.add(退出);
add(pSouth,BorderLayout.SOUTH);
validate();
setBounds(100,200,360,270);
}
public void actionPerformed(ActionEvent e)
{
if(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))
{
String warning="该生成绩已存在,请到修改页面修改!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
else
{
String m="学生成绩将被录入!";
int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
String chinese=语文.getText();
String english=英语.getText();
String math=数学.getText();
学生成=new StudentG();
学生成.setNumber(number);
学生成.setChinese(chinese);
学生成.setEnglish(english);
学生成.setMath(math);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
基本成绩表.put(number,学生成);
outTwo.writeObject(基本成绩表);
outTwo.close();
outOne.close();
学号.setText(null);
语文.setText(null);
数学.setText(null);
英语.setText(null);
}
catch(Exception ee)
{
System.out.println(ee);
}
}
}
}
else
{
String warning="必须要输入学号!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
}
if(e.getSource()==重置)
{
学号.setText(null);
语文.setText(null);
数学.setText(null);
英语.setText(null);
}
if(e.getSource()==退出)
{
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -