當前位置:編程學習大全網 - 源碼下載 - 求畢業設計及論文“基於Java的學生信息管理系統的設計與實現”

求畢業設計及論文“基於Java的學生信息管理系統的設計與實現”

僅僅給妳個參考

//Java Group Project_StudentManagement源碼

//NetBeans IDE 6.5 環境

package studentmanager;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.util.*;

class Student implements java.io.Serializable{

String number,name,specialty,grade,borth,sex;

public Student(){};

public void setNumber(String number){ this.number=number;}

public String getNumber(){ return number;}

public void setName(String name){ this.name=name;}

public String getName(){ return name;}

public void setSex(String sex){ this.sex=sex;}

public String getSex(){ return sex;}

public void setSpecialty(String specialty){ this.specialty=specialty;}

public String getSpecialty(){ return specialty;}

public void setGrade(String grade){ this.grade=grade;}

public String getGrade(){ return grade;}

public void setBorth(String borth){ this.borth=borth;}

public String getBorth(){ return borth;}

}

public class StudentManager extends JFrame{

JLabel lb=new JLabel("錄入請先輸入記錄,查詢、刪除請先輸入學號,修改是對查詢" +

"內容改後的保存!");

JTextField 學號,姓名,專業,年級,出生;

JRadioButton 男,女;

ButtonGroup group=null;

JButton 錄入,查詢,刪除,修改,顯示;

JPanel p1,p2,p3,p4,p5,p6,pv,ph;

Student 學生=null;

Hashtable 學生散列表=null;

File file=null;

FileInputStream inOne=null;

ObjectInputStream inTwo=null;

FileOutputStream outOne=null;

ObjectOutputStream outTwo=null;

public StudentManager(){

super("學生基本信息管理系統");

學號=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("查詢");

刪除=new JButton("刪除");

修改=new JButton("修改");

顯示=new JButton("顯示");

錄入.addActionListener(new InputAct());

查詢.addActionListener(new InquestAct());

修改.addActionListener(new ModifyAct());

刪除.addActionListener(new DeleteAct());

顯示.addActionListener(new ShowAct());

修改.setEnabled(false);

p1=new JPanel();

p1.add(new JLabel("學號:",JLabel.CENTER));

p1.add(學號);

p2=new JPanel();

p2.add(new JLabel("姓名:",JLabel.CENTER));

p2.add(姓名);

p3=new JPanel();

p3.add(new JLabel("性別:",JLabel.CENTER));

p3.add(男);

p3.add(女);

p4=new JPanel();

p4.add(new JLabel("專業:",JLabel.CENTER));

p4.add(專業);

p5=new JPanel();

p5.add(new JLabel("年級:",JLabel.CENTER));

p5.add(年級);

p6=new JPanel();

p6.add(new JLabel("出生:",JLabel.CENTER));

p6.add(出生);

pv=new JPanel();

pv.setLayout(new GridLayout(6,1));

pv.add(p1);

pv.add(p2);

pv.add(p3);

pv.add(p4);

pv.add(p5);

pv.add(p6);

ph=new JPanel();

ph.add(錄入);

ph.add(查詢);

ph.add(修改);

ph.add(刪除);

ph.add(顯示);

file=new File("學生信息.txt");

學生散列表=new Hashtable();

if(!file.exists()){

try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out);

objectOut.writeObject(學生散列表);

objectOut.close();

out.close();

}

catch(IOException e){}

}

Container con=getContentPane();

con.setLayout(new BorderLayout());

con.add(lb, BorderLayout.NORTH);

con.add(pv, BorderLayout.CENTER);

con.add(ph, BorderLayout.SOUTH);

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){

修改.setEnabled(false);

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){System.out.println("創建散列表出現問題!");}

if(學生散列表.containsKey(number)){

String warning="該生信息已存在,請到修改頁面修改!";

JOptionPane.showMessageDialog(null,warning,"警告",

JOptionPane.WARNING_MESSAGE);

}//end if1

else{

String m="該生信息將被錄入!";

int ok=JOptionPane.showConfirmDialog(null,m,"確認",

JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

String name=姓名.getText();

String specialty=專業.getText();

String grade=年級.getText();

String borth=出生.getText();

String sex=null;

if(男.isSelected()){sex=男.getText();}

else{sex=女.getText();}

學生=new Student();

學生.setNumber(number);

學生.setName(name);

學生.setSpecialty(specialty);

學生.setGrade(grade);

學生.setBorth(borth);

學生.setSex(sex);

try{

outOne=new FileOutputStream(file);

outTwo=new ObjectOutputStream(outOne);

學生散列表.put(number,學生);

outTwo.writeObject(學生散列表);

outTwo.close();

outOne.close();

}

catch(Exception ee){System.out.println("輸出散列表出現問題!");}

學號.setText(null);

姓名.setText(null);

專業.setText(null);

年級.setText(null);

出生.setText(null);

}

}//end else1

}//end if0

else{

String warning="必須輸入學號!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}//end else0

}//end actionPerformed

}//end class

class InquestAct implements ActionListener{

public void actionPerformed(ActionEvent e){

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){System.out.println("散列表有問題!");}

if(學生散列表.containsKey(number)){

修改.setEnabled(true);

Student stu=(Student)學生散列表.get(number);

姓名.setText(stu.getName());

專業.setText(stu.getSpecialty());

年級.setText(stu.getGrade());

出生.setText(stu.getBorth());

if(stu.getSex().equals("男")){男.setSelected(true);}

else{女.setSelected(true);}

}

else{

修改.setEnabled(false);

String warning="該學號不存在!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

else{

修改.setEnabled(false);

String warning="必須輸入學號!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

}

class ModifyAct implements ActionListener{

public void actionPerformed(ActionEvent e){

String number=學號.getText();

String name=姓名.getText();

String specialty=專業.getText();

String grade=年級.getText();

String borth=出生.getText();

String sex=null;

if(男.isSelected()){sex=男.getText();}

else{sex=女.getText();}

Student 學生=new Student();

學生.setNumber(number);

學生.setName(name);

學生.setSpecialty(specialty);

學生.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("錄入修改出現異常!");

修改.setEnabled(false);

}

}

}

class DeleteAct implements ActionListener{

public void actionPerformed(ActionEvent e){

修改.setEnabled(false);

String 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)){

Student stu=(Student)學生散列表.get(number);

姓名.setText(stu.getName());

專業.setText(stu.getSpecialty());

年級.setText(stu.getGrade());

出生.setText(stu.getBorth());

if(stu.getSex().equals("男")){男.setSelected(true);}

else{女.setSelected(true);}

}

String m="確定要刪除該學生的記錄嗎?";

int ok=JOptionPane.showConfirmDialog(null,m,"確認",

JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

學生散列表.remove(number);

try{

outOne=new FileOutputStream(file);

outTwo=new ObjectOutputStream(outOne);

outTwo.writeObject(學生散列表);

outTwo.close();

outOne.close();

學號.setText(null);

姓名.setText(null);

專業.setText(null);

年級.setText(null);

出生.setText(null);

}

catch(Exception ee){System.out.println(ee);}

}

else if(ok==JOptionPane.NO_OPTION){

學號.setText(null);

姓名.setText(null);

專業.setText(null);

年級.setText(null);

出生.setText(null);

}

else{

String warning="該學號不存在!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

else{

String warning="必須輸入學號!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

}

class ShowAct implements ActionListener{

public void actionPerformed(ActionEvent e){

new StudentShow(file);

}

}

class StudentShow extends JDialog{

Hashtable 學生散列表= null;

JTextArea 顯示=null;

FileInputStream inOne=null;

ObjectInputStream inTwo=null;

File file=null;

public StudentShow(File file){

super(new JFrame(),"顯示對話框");

this.file=file;

顯示=new JTextArea(16,30);

try{

inOne=new FileInputStream(file);

inTwo=new ObjectInputStream(inOne);

學生散列表=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exception ee){}

if(學生散列表.isEmpty())顯示.append("目前還沒有學生的信息記錄!\n");

else{

顯示.setText("學號 姓名 性別 專業 年級 出生\n");

for(Enumeration enm=學生散列表.elements();enm.hasMoreElements();){

Student stu=(Student)enm.nextElement();

String sex="";

if(stu.getSex().equals("男"))sex="男";

else sex="女";

String str=stu.getNumber()+","+stu.getName()+","+sex+","

+stu.getSpecialty()+","+stu.getGrade()+","+stu.getBorth()+"\n";

顯示.append(str);

}

}

JScrollPane scroll=new JScrollPane(顯示);

Container con=getContentPane();

con.add("Center",scroll);

con.validate();

setVisible(true);

setBounds(200,200,400,300);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){setVisible(false);}

}

);

}

}

}

  • 上一篇:TLS過程(DH 非對稱加密)
  • 下一篇:電腦藍屏怎麽解決?錯誤代碼是stop:0*00000004E
  • copyright 2024編程學習大全網