//Java group project _ studentmanagement source code
//NetBeans IDE 6.5 environment
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, major, grade, birth, gender;
Public students () {};
public void set number(String number){ this . number = number; }
Public string getnumber () {returnnumber; }
public void set name(String name){ this . name = name; }
Public string getname () {returnname; }
public void setSex(String sex){ this . sex = sex; }
Public string getsex () {returnsex; }
Public void setSpecialty (string specialty) {this. specialty = specialty; }
The public string getspecialty () {returnspecialty; }
public void set grade(String grade){ this . grade = grade; }
Common string getgrade () {returngrade; }
public void set borth(String borth){ this . borth = borth; }
Public string getborth () {returnborth; }
}
Public class StudentManager extension JFrame{
Jlabelb = newjlabel ("Please enter the record for entry, enter the student number for query deletion, and change it to query"+
"Save the changed contents!" );
JTextField student number, name, major, grade, birth;
JRadioButton, male and female;
ButtonGroup group = null
Input, query, deletion, modification and display of JButton;
JPanel p 1,p2,p3,p4,p5,p6,pv,ph;
Student student = null
Hashtable student hash table = null
File file = null
FileInputStream inOne = null
ObjectInputStream inTwo = null
FileOutputStream outOne = null
ObjectOutputStream outTwo = null
public StudentManager(){
Super ("student basic information management system");
Student ID = new jtextfield (10);
name = new JTextField( 10);
major = new JTextField( 10);
grade = new JTextField( 10);
birth = new JTextField( 10);
group = new button group();
Male =new JRadioButton ("male ",true);
Female =new JRadioButton ("female", false);
Group.add (male);
Group.add (female);
input = new JButton(" input ");
query = new JButton(" query ");
delete = new JButton(" delete ");
modify = new JButton(" modify ");
display = new JButton(" display ");
Enter. addActionListener(new inputtact());
Inquiry. Addactionlistener (new inquiry bill ());
Modify. addActionListener(new modify act());
Delete. addActionListener(new DeleteAct());
Show. addActionListener(new ShowAct());
Modify. set enabled(false);
p 1 = new JPanel();
P 1.add (new JLabel ("student number:", JLabel. Center));
P 1.add (student number);
p2 = new JPanel();
P2.add (new JLabel ("name: ",JLabel. Center));
P2.add (name);
P3 = new JPanel();
P3.add (New JLabel ("Gender:", JLabel. Center));
P3.add (male);
P3.add (female);
P4 = new JPanel();
P4.add(new JLabel ("major:",JLabel。 Center));
P4.add (major);
P5 = new JPanel();
P5.add(new JLabel ("grade:",JLabel。 Center));
P5.add (grade);
P6 = new JPanel();
P6.add (New JLabel ("Born:", JLabel. Center));
P6.add (birth);
PV = new JPanel();
pv.setLayout(new GridLayout(6, 1));
PV . add(p 1);
PV . add(p2);
PV . add(P3);
PV . add(P4);
PV . add(P5);
PV . add(P6);
ph = new JPanel();
Ph.add (input);
Ph.add (query);
Ph.add (modified);
Ph.add (deleted);
Ph.add (display);
File=new File ("student information. txt ");
Student hash table = new hash table ();
If (! file.exists()){
Try {
file output stream out = new file output stream(file);
object output stream object out = new object output stream(out);
ObjectOut.writeObject (student hash table);
object out . close();
out . close();
}
catch(IOException e){}
}
container con = getContentPane();
con . set layout(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);
set visible(true);
}
public static void main(String[]args){ new student manager(); }
Class InputAct implements ActionListener{
public void action performed(action event e){
Modify. set enabled(false);
String number = "";
Number = student number. getText();
if(number . length()& gt; 0){
Try {
InOne=new FileInputStream (file);
int wo = new ObjectInputStream(inOne);
student Hashtable =(Hashtable)int wo . read object();
inone . close();
int wo . close();
}
Catch (exceptionee) {system。 Out.println ("There was a problem creating the hash table!" ); }
If (student hash table. Contains keys (numbers) (
String warning= "The student information already exists, please go to the modify page to modify it!" ;
Joptionpane。 Displays the message dialog box (empty, warning, "warning",
JOptionPane。 WARNING _ MESSAGE);
}//end if 1
Otherwise {
String m= "Student information will be entered!" ;
Intok = Joption pane. ShowConfirmilog (null, m, "confirm",
JOptionPane。 YES_NO_OPTION,JOptionPane。 Information _ message);
if(ok==JOptionPane。 Yes _ option) {
String name = name. getText();
String major = major. getText();
string grade = grade . gettext();
Stringborn = born. getText();
String sex = null
if(male . is selected()){ sex = male . gettext(); }
Else{sex= female. getText(); }
Students = freshmen ();
student SetNumber (number);
student SetName;
student SetSpecialty;
student SetGrade;
student Seth boss (borth);
student SetSex;
Try {
OutOne=new FileOutputStream (file);
out two = new object output stream(out one);
Hash table for students. Put ($ NUMBER, students);
OutTwo.writeObject (student hash table);
out two . close();
out one . close();
}
Catch (exceptionee) {system。 Out.println ("There is something wrong with the output hash table!" ); }
Student ID card. SetText (empty);
Name. SetText (empty);
Major. SetText (empty);
Grade. SetText (empty);
Born. SetText (empty);
}
}//end else 1
}//end if0
Otherwise {
String warning= "Student ID must be entered!" ;
JOptionPane.showMessageDialog (empty, warning,
"warning", jooptionpane warning _ message);
}//end else0
}//End the executed operation.
}//End class
Class inquiry method to realize ActionListener{
public void action performed(action event e){
String number = "";
Number = student number. getText();
if(number . length()& gt; 0){
Try {
InOne=new FileInputStream (file);
int wo = new ObjectInputStream(inOne);
student Hashtable =(Hashtable)int wo . read object();
inone . close();
int wo . close();
}
Catch (exceptionee) {system。 Out.println ("There is something wrong with the hash table!" ); }
If (student hash table. Contains keys (numbers) (
Modify. SetEnabled (true);
Student stu= (student) student hash table. get($ NUMBER);
Name. setText(stu . getname());
Major. setText(stu . get specialty());
Grade. setText(stu . get grade());
Born. setText(stu . getborth());
If(stu.getSex()。 Equal to ("male") {male. set selected(true); }
Else{ female. set selected(true); }
}
Otherwise {
Modify. set enabled(false);
String warning= "This student number does not exist!" ;
JOptionPane.showMessageDialog (empty, warning,
"warning", jooptionpane warning _ message);
}
}
Otherwise {
Modify. set enabled(false);
String warning= "Student ID must be entered!" ;
JOptionPane.showMessageDialog (empty, warning,
"warning", jooptionpane warning _ message);
}
}
}
Class ModifyAct implements ActionListener{
public void action performed(action event e){
String number = student number. getText();
String name = name. getText();
String major = major. getText();
string grade = grade . gettext();
Stringborn = born. getText();
String sex = null
if(male . is selected()){ sex = male . gettext(); }
Else{sex= female. getText(); }
Students = freshmen ();
student SetNumber (number);
student SetName;
student SetSpecialty;
student SetGrade;
student Seth boss (borth);
student SetSex;
Try {
OutOne=new FileOutputStream (file);
out two = new object output stream(out one);
Hash table for students. Put ($ NUMBER, students);
OutTwo.writeObject (student hash table);
out two . close();
out one . close();
Student ID card. SetText (empty);
Name. SetText (empty);
Major. SetText (empty);
Grade. SetText (empty);
Born. SetText (empty);
}
Catch (abnormal ee){
System.out.println ("Exception in entering and modifying!" );
Modify. set enabled(false);
}
}
}
Class DeleteAct implements ActionListener{
public void action performed(action event e){
Modify. set enabled(false);
String number = student number. getText();
if(number . length()& gt; 0){
Try {
InOne=new FileInputStream (file);
int wo = new ObjectInputStream(inOne);
student Hashtable =(Hashtable)int wo . read object();
inone . close();
int wo . close();
}
Catch (abnormal ee){}
If (student hash table. Contains keys (numbers) (
Student stu= (student) student hash table. get($ NUMBER);
Name. setText(stu . getname());
Major. setText(stu . get specialty());
Grade. setText(stu . get grade());
Born. setText(stu . getborth());
If(stu.getSex()。 Equal to ("male") {male. set selected(true); }
Else{ female. set selected(true); }
}
String m= "Are you sure you want to delete this student's record?" ;
Intok = Joption pane. ShowConfirmilog (null, m, "confirm",
JOptionPane。 YES_NO_OPTION,JOptionPane。 QUESTION _ MESSAGE);
if(ok==JOptionPane。 Yes _ option) {
Hash table for students. Removed ($ NUMBER);
Try {
OutOne=new FileOutputStream (file);
out two = new object output stream(out one);
OutTwo.writeObject (student hash table);
out two . close();
out one . close();
Student ID card. SetText (empty);
Name. SetText (empty);
Major. SetText (empty);
Grade. SetText (empty);
Born. SetText (empty);
}
catch(Exception ee){ system . out . println(ee); }
}
else if(ok==JOptionPane。 NO_OPTION){
Student ID card. SetText (empty);
Name. SetText (empty);
Major. SetText (empty);
Grade. SetText (empty);
Born. SetText (empty);
}
Otherwise {
String warning= "This student number does not exist!" ;
JOptionPane.showMessageDialog (empty, warning,
"warning", jooptionpane warning _ message);
}
}
Otherwise {
String warning= "Student ID must be entered!" ;
JOptionPane.showMessageDialog (empty, warning,
"warning", jooptionpane warning _ message);
}
}
}
Class ShowAct implements ActionListener{
public void action performed(action event e){
Freshman show (file);
}
}
How to extend JDialog{
Hashtable student hash table = null
JTextArea display = null
FileInputStream inOne = null
ObjectInputStream inTwo = null
File file = null
public StudentShow(File file){
Super(new JFrame (), "show dialog box");
this.file = file
Display =new JTextArea( 16,30);
Try {
InOne=new FileInputStream (file);
int wo = new ObjectInputStream(inOne);
student Hashtable =(Hashtable)int wo . read object();
inone . close();
int wo . close();
}
Catch (abnormal ee){}
If (student hash table. IsEmpty ()) display. Append ("There is no record of students' information yet! \ n ");
Otherwise {
Show. SetText ("student number, name, gender, professional level, birth \ n");
For(Enumeration enm= student hash table. elements(); enm . hasmoreelements(); ){
Student stu =(Student)enm . nextelement();
String sex =
If(stu.getSex()。 equals(" male "))sex = " male ";
Else sex= "female";
String str=stu.getNumber()+","+stu.getName()+","+sex+","
+stu.getSpecialty()+","+stu.getGrade()+","+stu . get borth()+" \ n ";
Show. Append (string);
}
}
Jscrollpane scroll = new jscrollpane (display);
container con = getContentPane();
Con.add ("center", scrolling);
con . validate();
set visible(true);
setBounds(200,200,400,300);
addWindowListener(new window adapter(){
public void window closing(window event e){ set visible(false); }
}
);
}
}
}