用java编写学生信息管理系统
- 格式:docx
- 大小:10.99 KB
- 文档页数:7
用java编写学生信息管理系统
import .*;
import
import .*;
import .*;
import .*;
class Stude nt impleme nts
String nu mber, name,specialty,grade,borth,sex;
public Stude nt(){};
public void setNumber(Stri ng nu mber){ =nu mber;}
public String getNumber(){ retur n nu mber;}
public void setName(Stri ng n ame){ =n ame;}
public String getName(){ retur n n ame;}
public void setSex(Stri ng sex){ =sex;}
public String getSex(){ retur n sex;}
public void setSpecialty(Stri ng specialty){ =specialty;}
public String getSpecialty(){ retur n specialty;}
public void setGrade(Stri ng grade){ =grade;}
public String getGrade(){ retur n grade;}
public void setBorth(Stri ng borth){ =borth;}
public Stri ng getBorth(){ retur n borth;}
}
public class Stude ntMa nager exte nds JFrame{
JLabel lb=new JLabel ("录入请先输入记录,查询、删除请先输入学号,修改是对查询 ”
+
"内容改后的保存! ”);
static JTextField Jnu mber, Jn ame,Jspecialty,Jgrade,Jborth;
static JRadioButt on boy,girl;
static Butt on Group group=nu II;
static JButton Log in, select,delete,update,show;
static JPa nel p1,p2,p3,p4,p5,p6,pv,ph;
static Stude nt stude nt=n ull;
static Hashtable Shashtable=nu II;
static File file=n ull;
static File In putStream inOne=n ull;
static Object In putStream in Two=n ull;
static FileOutputStream out One=n ull;
static ObjectOutputStream outTwo=n ull;
public Stude ntMa nager(){
super("学生基本信息管理系统”);
Jnu mber =new JTextField(10);
Jname =new JTextField(10); Jspecialty=new JTextField(10); Jgrade=new JTextField(10);
Jborth=new JTextField(10); group=new ButtonGroup(); boy=new JRadioButton(" 男 ",true);
girl=new JRadioButton(" 女 ",false); (boy);
(girl);
Login=new JButton(" 录入 "); select=new JButton(" 查询 "); delete=new JButton(" 删除
"); update=new JButton(" 修改 "); show=new JButton(" 显示 "); (new InputAct());
(new InquestAct());
(new ModifyAct());
(new DeleteAct());
(new ShowAct());
(false); p1=new JPanel();
(new JLabel("学号:",);
(Jnumber); p2=new JPanel(); (new JLabel("姓名:",);
(Jname); p3=new JPanel();
(new JLabel("性别:",);
(boy);
(girl);
p4=new JPanel();
(new JLabel("专业:",);
(Jspecialty); p5=new JPanel();
(new JLabel("年级:",);
(Jgrade); p6=new JPanel();
(new JLabel("出生:",);
(Jborth); pv=new JPanel();
(new GridLayout(6,1));
(p1);
(p2);
(p3);
(p4);
(p5);
(p6);
ph=new JPanel();
(Login);
(select);
(update);
(delete);
(show);
file=new File(" 学生信息 .txt");
Shashtable=new Hashtable();
if(!()){
try{
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out); (Shashtable);
();
();
}
catch(IOException e){}
}
Container con=getContentPane();
(new BorderLayout());
(lb, ;
(pv, ;
(ph, ;
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100,100,600,300);
setVisible(true);
}
public static void main(String[] args) {new StudentManager();}
class InputAct implements ActionListener{
public void actionPerformed(ActionEvent e){
(false);
String number="";
number=();
if()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
Shashtable=(Hashtable)();
();
();
}
catch(Exception ee){" 创建散列表出现问题! ");} if(number)){
String warning=" 该生信息已存在,请到修改页面修改! (null,warning," 警告 ",
J
}quals(” 男")){(true);}
else{(true);}
}
else{
(false);
String warning=" 该学号不存在! ";
(null,warning,
"警告 ",;
}
}
else{
(false);
String warning=" 必须输入学号! ";
(null,warning,
"警告 ",;
}
}
}
class ModifyAct implements ActionListener{ public void actionPerformed(ActionEvent e){
String number=();
String name=();
String specialty=();
String grade=();
String borth=();
String sex=null;
if()){sex=();}
else{sex=();}
Student 学生 =new Student();
学生 .setNumber(number);
学生 .setName(name);
学生 .setSpecialty(specialty);
学生 .setGrade(grade);
学生 .setBorth(borth);
学生 .setSex(sex);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
(number, 学生 );
(Shashtable);
();
();
(null);
(null);
(null);
(null);
(null);
}
catch(Exception ee){
"录入修改出现异常 !");
(false);
}
}
}
class DeleteAct implements ActionListener{
public void actionPerformed(ActionEvent e){
(false);
String number=();
if()>0){