import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class StudentSituation extends Jpanel implements ActionListener
{ Hashable 基本信息表=null; //存放学生基本信息的散列表。
JTextField 学号,姓名,专业,年级,出生; //输入基本信息的文本条。
JRadioButton 男,女;
Student 学生=null;
ButtonGroup group=null;
JButton 录入,重置; FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
ObjectOutputStream outTwo=null;
File file=null; //存放散列表的文件。
public StudentSituation(File file)
{
this.file=file;
学号=new JTextField(10);
姓名=new JTextField(10);
专业=new JTextField(10);
年级=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
录入=new JButton("录入");
重置=new JButton("重置");
录入.addActionListener(this);
重置.addActionListener(this);
Box box1=Box.createHorizontalBox(); //创建6个水平Box容器
box1.add(new JLabel("学号:",JLabel.CENTER));
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 box5=Box.createHorizontalBox();
box5.add(new JLabel("年级: ",JLabel.CENTER));
box5.add(年级);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("出生: ",JLabel.CENTER));
box6.add(出生);
Box boxH=Box.createVerticalBox(); //创建一个垂直Box容器,其中从上向下 //排列6个水平Box容器。
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);
boxH.add(Box.createVerticalGlue()); //垂直Box容器内的组件靠上对齐。
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanel pSouth=new JPanel();
pSouth.add(录入);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
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(); //首先到文件中 //读取Hashtable对象。
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 name=姓名.getText();
String discipling=专业.getText();
String grade=年级.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected())
{
sex=男.getText();
}
else
{
sex=女.getText();
}
学生=new Student();
学生.setNumber(number);
学生.setName(name);
学生.setDiscipling(discipling);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
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);
出生.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);
出生.setText(null);
}
}
}
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class StudentSituation extends Jpanel implements ActionListener
{ Hashable 基本信息表=null; //存放学生基本信息的散列表。
JTextField 学号,姓名,专业,年级,出生; //输入基本信息的文本条。
JRadioButton 男,女;
Student 学生=null;
ButtonGroup group=null;
JButton 录入,重置; FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
ObjectOutputStream outTwo=null;
File file=null; //存放散列表的文件。
public StudentSituation(File file)
{
this.file=file;
学号=new JTextField(10);
姓名=new JTextField(10);
专业=new JTextField(10);
年级=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
录入=new JButton("录入");
重置=new JButton("重置");
录入.addActionListener(this);
重置.addActionListener(this);
Box box1=Box.createHorizontalBox(); //创建6个水平Box容器
box1.add(new JLabel("学号:",JLabel.CENTER));
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 box5=Box.createHorizontalBox();
box5.add(new JLabel("年级: ",JLabel.CENTER));
box5.add(年级);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("出生: ",JLabel.CENTER));
box6.add(出生);
Box boxH=Box.createVerticalBox(); //创建一个垂直Box容器,其中从上向下 //排列6个水平Box容器。
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);
boxH.add(Box.createVerticalGlue()); //垂直Box容器内的组件靠上对齐。
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanel pSouth=new JPanel();
pSouth.add(录入);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
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(); //首先到文件中 //读取Hashtable对象。
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 name=姓名.getText();
String discipling=专业.getText();
String grade=年级.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected())
{
sex=男.getText();
}
else
{
sex=女.getText();
}
学生=new Student();
学生.setNumber(number);
学生.setName(name);
学生.setDiscipling(discipling);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
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);
出生.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);
出生.setText(null);
}
}
}
Hashable,Student,学号--?不知道你这个东西在哪里
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class StudentSituation extends Jpanel implements ActionListener
{ Hashable 基本信息表=null; //存放学生基本信息的散列表。
JTextField 学号,姓名,专业,年级,出生; //输入基本信息的文本条。
JRadioButton 男,女;
Student 学生=null;
ButtonGroup group=null;
JButton 录入,重置; FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
ObjectOutputStream outTwo=null;
File file=null; //存放散列表的文件。
public StudentSituation(File file)
{
this.file=file;
学号=new JTextField(10);
姓名=new JTextField(10);
专业=new JTextField(10);
年级=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
录入=new JButton("录入");
重置=new JButton("重置");
录入.addActionListener(this);
重置.addActionListener(this);
Box box1=Box.createHorizontalBox(); //创建6个水平Box容器
box1.add(new JLabel("学号:",JLabel.CENTER));
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 box5=Box.createHorizontalBox();
box5.add(new JLabel("年级: ",JLabel.CENTER));
box5.add(年级);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("出生: ",JLabel.CENTER));
box6.add(出生);
Box boxH=Box.createVerticalBox(); //创建一个垂直Box容器,其中从上向下 //排列6个水平Box容器。
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);
boxH.add(Box.createVerticalGlue()); //垂直Box容器内的组件靠上对齐。
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanel pSouth=new JPanel();
pSouth.add(录入);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
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(); //首先到文件中 //读取Hashtable对象。
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 name=姓名.getText();
String discipling=专业.getText();
String grade=年级.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected())
{
sex=男.getText();
}
else
{
sex=女.getText();
}
学生=new Student();
学生.setNumber(number);
学生.setName(name);
学生.setDiscipling(discipling);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
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);
出生.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);
出生.setText(null);
}
}
}
还是不行啊,提示 需要“class"或”interface",大家帮帮我啊,我们考试考学籍管理系统,这是第一个程序就不会,我怕挂啊,JAVA是考查课,但我想好好学习啊!!!希望大家指教!!!!