Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Java Student Record System Problem

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java Student Record System Problem

    I have written a program student record system but can not save data to view or submit record.
    Able to run the program but failed to submit record or view pre-submitted records.
    Student.java
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
     
    class Student extends Frame implements ActionListener
    {
        String greeding="";
        Button btnNewStudent;
        Button btnSubmit;
        Button btnView;
        Label lblStudentName;
        Label lblStudentAge;
        Label lblStudentAddr;
        Label lblStudentGender;
        Label lblProgram;
        TextField txtStudentName;
        TextField txtStudentAge;
        TextArea txtStudentAddr;
        TextArea txtAns;
        CheckboxGroup ChkGrp;
        Checkbox chkMale,chkFemale;
        Checkbox chkGameDesign,chkComputerStudies,chkHotelManagement,chkArtAndDesign;
         Student(String Studentname)
        {  
            super(Studentname);
            setLayout(new GridLayout(3,2));
     
            lblStudentName = new Label("Name: ");
            lblStudentAge = new Label("Age: ");
            lblStudentAddr = new Label("Address : ");
            lblStudentGender = new Label("Gender: ");
            lblProgram = new Label("Qualification: ");
            txtStudentName = new TextField(20);
            txtStudentAge = new TextField(20);
            txtStudentAddr = new TextArea();
            ChkGrp = new CheckboxGroup();
            chkMale = new Checkbox("Male",ChkGrp,false);
            chkFemale = new Checkbox("Female",ChkGrp,false);
            chkGameDesign = new Checkbox("Game Design");
            chkComputerStudies = new Checkbox("Computer Studies");
            chkHotelManagement = new Checkbox("Hotel Management");
            chkArtAndDesign = new Checkbox("Art and Design");
            btnNewStudent = new Button("NEW");
            btnSubmit = new Button("SUBMIT");
            btnView = new Button("VIEW");
     
            btnNewStudent.addActionListener(this);
            btnSubmit.addActionListener(this);
            btnView.addActionListener(this);
     
            add(lblStudentName);
            add(txtStudentName);
            add(lblStudentAge);
            add(txtStudentAge);
            add(lblStudentAddr);
            add(txtStudentAddr);
            add(lblStudentGender);
            add(chkMale);
            add(chkFemale);
            add(lblProgram);
            add(chkGameDesign);
            add(chkComputerStudies);
            add(chkHotelManagement);
            add(chkArtAndDesign);
     
            add(btnNewStudent);
            add(btnSubmit);
            add(btnView);
     
            txtAns = new TextArea();
            add(txtAns);
     
        }  
     
        public void 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=txtStudentName.getText().trim();
                    dos.writeUTF(s);
     
                    dos.writeInt(Integer.parseInt(txtStudentAge.getText()));
     
                    s=txtStudentAddr.getText();
     
                    dos.writeUTF(s);
                    if(chkMale.getState())
                        dos.writeUTF("Male ");
                    if(chkFemale.getState())
                        dos.writeUTF("Female ");
     
                    s="";                  
                    if(chkGameDesign.getState())
                        s="Game Design ";  
     
                    if(chkComputerStudies.getState())
                        s+="Computer Studies ";                      
     
                    if(chkHotelManagement.getState())
                        s+="Hotel Management ";  
     
                    if(chkArtAndDesign.getState())
                        s+="Art And Design ";  
     
                    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(txtStudentName.getText().trim()))
                          {
                            txtStudentAge.setText(age+"");                  
                            txtStudentAddr.setText(addr);
                            if(gender.equals("Male "))
                                chkMale.setState(true);
                            else
                                chkFemale.setState(true);
                            while(Program.charAt(i)!='!')
                            {
                                j=qual.indexOf(' ');
                                tmp = qual.substring(i,j);
     
                                if(tmp.equals("Game Design"))
                                    chkGameDesign.setState(true);                  
     
                                if(tmp.equals("Computer Studies"))
                                    chkComputerStudies.setState(true);                  
     
                                if(tmp.equals("Hotel Management"))
                                    chkHotelManagement.setState(true);                  
     
                                if(tmp.equals("Art And Design"))
                                    chkArtAndDesign.setState(true);
                                i=j+1;
                            }
                            break;
                        }
                    }
                    Fin.close();  
                }
     
                if(str.equals("NEW"))
                {
                    txtStudentName.setText("");
                    txtStudentAge.setText("");                  
                    txtStudentAddr.setText("");
                    chkMale.setState(false);
                    chkFemale.setState(false);
                    chkGameDesign.setState(false);                  
                    chkComputerStudies.setState(false);                  
                    chkHotelManagement.setState(false);                  
                    chkArtAndDesign.setState(false);
                }
            }
            catch(Exception e)
            {
                System.out.println("The Exception Is : " +e);
            }
     
        }
     
    }

    Record.java
    class Record
    {
     
        public static void main (String args[])
        {
            try{
            Student F = new Student("Record");
            F.setSize(400,400);
            F.show();
            }catch(Exception e)
            {
                System.out.println(e);
            }
        }  
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Student Record System Problem

    You need to narrow your problem down further. Where is the code that saves the data? Can you isolate it into an SSCCE that demonstrates the problem? Have you tried stepping through this with a debugger or by hand, or just adding print statements to figure out when the program's execution differs from your expectations?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Student Record System Problem

    Actually the only problem is everything works except the New, Submit and View Button.Screen Shot 2014-02-19 at 10.09.56 PM.jpg

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Student Record System Problem

    Okay, cool. And have you narrowed your problem down into an SSCCE for each button? Have you stepped through the code for each button? Where does the program's execution for each button differ from what you'd expect?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Student Record System Problem

    After typing the data and click submit or new to clear the page I get this error on Java Console:
    "Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    Program cannot be resolved

    at Student.actionPerformed(Student.java:151)
    at java.awt.Button.processActionEvent(Button.java:392 )
    at java.awt.Button.processEvent(Button.java:360)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4776)
    at java.awt.Component.dispatchEvent(Component.java:46 04)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:717)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:676)
    at java.awt.EventQueue$2.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:86)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:690)
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:86)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 687)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)"

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Student Record System Problem

    That means you have a compilation error. This is not a runtime error. You can get the compiler error by running javac on your java file. If you don't know how to get to a compiler error in an IDE yet, you shouldn't be using an IDE. Use the command line instead.

    But since that advice is almost always ignored, your IDE is probably telling you about the compiler error. Look for red squiggly lines on the line in questions.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Highschool student in need of help with array problem! Please Help!
    By pegasus949 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 5th, 2013, 06:36 PM
  2. problem of remove student from list
    By pig-rabbit in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 29th, 2012, 07:14 AM
  3. Replies: 3
    Last Post: August 30th, 2012, 02:38 PM
  4. Replies: 1
    Last Post: August 29th, 2012, 09:35 AM
  5. Replies: 0
    Last Post: April 6th, 2012, 04:14 PM

Tags for this Thread