Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Networking TechnologyRSS Feeds

GUI application in java, which enter the details of a student and on the submit display the details of the student

Posted By: Freya Brown     Category: Java     Views: 44452

Write a GUI application in java, which enter the details of a student and on the submit display the details of the student.(Student details is like bio-data, it contains name, address, phone, educational details,project details etc. ) Create three button in the GUI new, submit, view. When the user click the submit button it stores the information of the
student in the file. If the student press the new button it stores the information of the new student.(stored that information by any separator.) when View it show all the details of a student

Code for GUI application in java, which enter the details of a student and on the submit display the details of the student in Java

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

class Frame1 extends Frame implements ActionListener
{
    String msg="";
    Button btnNew,btnSubmit,btnView;
    Label lblName,lblAge,lblAddr,lblGender,lblQua;
    TextField txtName,txtAge;
    TextArea txtAddr,txtAns;
    CheckboxGroup ChkGrp;
    Checkbox chkMale,chkFemale;
    Checkbox chkMca,chkBca,chkBba,chkMba;
 
     Frame1(String name)
    {    
        super(name);
        setLayout(new GridLayout(3,2));

        lblName = new Label("Name: ");
        lblAge = new Label("Age: ");
        lblAddr = new Label("Address : ");
        lblGender = new Label("Gender: ");
        lblQua = new Label("Qualification: ");
        txtName = new TextField(20);
        txtAge = new TextField(20);
        txtAddr = new TextArea();
        ChkGrp = new CheckboxGroup();
        chkMale = new Checkbox("Male",ChkGrp,false);
        chkFemale = new Checkbox("Female",ChkGrp,false); 
        chkMca = new Checkbox("MCA");
        chkBca = new Checkbox("BCA");
        chkMba = new Checkbox("MBA");
        chkBba = new Checkbox("BBA");
        btnNew = new Button("NEW");
        btnSubmit = new Button("SUBMIT");
        btnView = new Button("VIEW");
        
        btnNew.addActionListener(this);
        btnSubmit.addActionListener(this);
        btnView.addActionListener(this);

        add(lblName);
        add(txtName);
        add(lblAge);
        add(txtAge);
        add(lblAddr);
        add(txtAddr);
        add(lblGender);
        add(chkMale);
        add(chkFemale);
        add(lblQua);
        add(chkBca);
        add(chkBba); 
        add(chkMca);
        add(chkMba); 
    
        add(btnNew);
        add(btnSubmit);
        add(btnView);
        
        txtAns = new TextArea();
        add(txtAns);
        
    }    
        
    publicvoid actionPerformed(ActionEvent ae)
    {
        String s="";
        boolean b;
        FileInputStream Fin;
        DataInputStream dis;
        FileOutputStream Fout;
        DataOutputStream dos;
        
        try
        {
            Fout = new FileOutputStream("Biodata.txt",true);
            dos = new DataOutputStream(Fout);
        
            String str = ae.getActionCommand();
            if(str.equals("SUBMIT"))
            {
            
                s=txtName.getText().trim();
                dos.writeUTF(s);
            
                dos.writeInt(Integer.parseInt(txtAge.getText()));

                s=txtAddr.getText();
                
                dos.writeUTF(s);
                if(chkMale.getState())
                    dos.writeUTF("Male ");
                if(chkFemale.getState())
                    dos.writeUTF("Female ");

                s="";                    
                if(chkMca.getState())
                    s="MCA ";    
                                
                if(chkBca.getState())
                    s+="BCA ";                        

                if(chkBba.getState())
                    s+="BBA ";    
                    
                if(chkMba.getState())
                    s+="MBA ";    
                    
                s+="!";
                dos.writeUTF(s);
                Fout.close();
            } 
            
            if(str.equals("VIEW"))
            {
                String tmp,name,addr,gender,qual;
                int age;
                Fin = new FileInputStream("Biodata.txt");
                dis = new DataInputStream(Fin);

        
                int i=0,j;
                
                while(Fin.available()>0)
                {
                    name = dis.readUTF();
                    age  = dis.readInt();
                    addr = dis.readUTF();
                    gender = dis.readUTF();
                    qual = dis.readUTF();

                    if(name.equals(txtName.getText().trim()))
                      {
                        txtAge.setText(age+"");                    
                        txtAddr.setText(addr);
                        if(gender.equals("Male "))
                            chkMale.setState(true);
                        else
                            chkFemale.setState(true);
                        while(qual.charAt(i)!='!')
                        {
                            j=qual.indexOf(' ');
                            tmp = qual.substring(i,j);
    
                            if(tmp.equals("MCA"))
                                chkMca.setState(true);                    

                            if(tmp.equals("BCA"))
                                chkBca.setState(true);                    

                            if(tmp.equals("BBA"))
                                chkBba.setState(true);                    

                            if(tmp.equals("MBA"))
                                chkMba.setState(true);
                            i=j+1;
                        }
                        break;
                    }
                }
                Fin.close();    
            }

            if(str.equals("NEW"))
            {
                txtName.setText("");
                txtAge.setText("");                    
                txtAddr.setText("");
                chkMale.setState(false);
                chkFemale.setState(false);
                chkMca.setState(false);                    
                chkBca.setState(false);                    
                chkBba.setState(false);                    
                chkMba.setState(false);
            }
        }
        catch(Exception e)
        {
            System.out.println("The Exception Is : " +e);
        }

    }

}

class Bio2
{

    publicstaticvoid main(String args[])
    {
        try{
        Frame1 F = new Frame1("Biodata");
        F.setSize(400,400);
        F.show();
        }catch(Exception e)
        {
            System.out.println(e);
        }
    }    

}
  
Share: 



Freya Brown
Freya Brown author of GUI application in java, which enter the details of a student and on the submit display the details of the student is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Mari Michael from United States Comment on: Sep 25
age wont show in the textfile,,, EOF error, out of reach error....please fix this, need badly =) thanks so much

View All Comments