Write a program that will allow tutors to record tutoring activities. A tutor needs to keep track of who come for help (name, student ID), started at what time (sign-in time), ended at what time (sign-out time), for what course, his/her professor name, a short description of the problems he/she needs help with. The information should be saved and retriveable. Must Be in GUI

I had it working last night and I made some changes to it this morning.

Course.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

@SuppressWarnings("serial")
public class Course extends JPanel implements ActionListener {

    JPanel panel;
    JLabel courseNameLabel;
    JLabel descriptionLabel;
    JLabel studentID;
    JLabel studentName;
    JLabel ProfessorName;
    JTextField profJTextField;
    JTextField courseName;
    JTextField description;
    JButton button;
    JFrame frame = new JFrame();


    public Course(Student student) {
        // TODO Auto-generated constructor stub
        panel = new JPanel();
        button = new JButton("Submit");
        button.addActionListener(this);
        courseNameLabel = new JLabel("Please course name: ");
        courseName = new JTextField(20);
        descriptionLabel = new JLabel("Please course description: ");
        description = new JTextField(20);
        ProfessorName = new JLabel("Enter the Prof name: ");
        profJTextField = new JTextField(20);
        studentName = new JLabel(student.studentName.getText());
        studentID = new JLabel(student.studendField.getText());
        panel.add(studentName);
        panel.add(studentID);
        panel.add(courseNameLabel);
        panel.add(courseName);
        panel.add(descriptionLabel);
        panel.add(description);
        panel.add(ProfessorName);
        panel.add(profJTextField);
        panel.add(button);
        frame.add(panel);
        frame.setVisible(true);
        frame.setSize(300, 300);
    frame.setLocation(100, 100);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        if (e.getSource() == button) {
            new TimeSheet(this);
            frame.setVisible(false);
        }

    }
}

Student.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.swing.*;

@SuppressWarnings("serial")
public class Student extends JFrame implements ActionListener {

    JPanel panel;
    JLabel label;
    JLabel StudendId;
    JTextField studendField;
    JTextField studentName;
    JButton button;
    JLabel info;
    public Student(){
        button=new JButton("Submit");
        button.addActionListener(this);
        info=new JLabel("User Has already logout.Thank You !!!");
        label = new JLabel("Please enter student's name: ");
        studentName = new JTextField(10);
        StudendId = new JLabel("Please enter student's Id: ");
        studendField = new JTextField(10);
        panel = new JPanel();
        panel.add(label);
        panel.add(studentName);
        panel.add(StudendId);
        panel.add(studendField);
        panel.add(button);
        panel.add(info).setVisible(false);
        add(panel);
        pack();
        setVisible(true);
        setSize(325, 150);
    setLocation(500, 300);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        if(e.getSource()==button)
        {

            File file=new File("output.txt");
            int count=0;
             try {
                Scanner scanner=new Scanner(file);
                while(scanner.hasNextLine())
                {
                    String temp=scanner.nextLine();
                    String temAString[]=temp.split("\\s");
                    System.out.println(temAString[3]);
                    if(temAString[3].equalsIgnoreCase(studendField.getText()))
                    {
                         panel.add(info).setVisible(true);
                         count++;
                         break;
                    }

                }
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
             if(count==0) 
                {
                    new Course(this);

                }
        }

    }
    public static void main(String args[])
    {
        Student student=new Student();

    }

}

TimeSheet.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;



/**
 *
 * @author acc
 */
@SuppressWarnings("serial")
public class TimeSheet extends JFrame implements ActionListener{

    JFrame frame;
    JPanel panel;
    JLabel courseNameLabel;
    JLabel studentID;
    JLabel studentName;
    JLabel ProfessorName;
    JLabel startTime;
    JButton button;
    public TimeSheet(Course course)
    {
        panel =new JPanel();
        frame=new JFrame();
        courseNameLabel=new JLabel(course.courseName.getName());
        studentID=new JLabel(course.studentID.getText());
        studentName=new JLabel(course.studentName.getText());
        ProfessorName=new JLabel(course.profJTextField.getName());
        startTime=new JLabel(new Date()+"");
        button=new JButton("Close");
        button.addActionListener(this);
        panel.add(ProfessorName);
        panel.add(studentID);
        panel.add(studentName);
        panel.add(courseNameLabel);
        panel.add(startTime);
        panel.add(button);
        frame.add(panel);
        frame.setVisible(true);
                pack();
        writingToFile();

    }
    public void writingToFile() {
        // TODO Auto-generated method stub
        File file=new File("output.txt"); 
         try {
            PrintWriter printWriter=new PrintWriter(file);

            printWriter.write("StudentName: "  + studentName.getText() + 
                    " StudentId: " + studentID.getText() + " ProfessorName: " + ProfessorName.getText()
                    + " Start Time :"+startTime.getText() +"\n");
            printWriter.close();

            }
        catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource()==this.button)
            frame.dispose();
    }

}

This is the error its giving me

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
    at tutorprogram.Student.actionPerformed(Student.java:58)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6289)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6054)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4652)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4482)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4482)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
    at java.awt.EventQueue.access$000(EventQueue.java:85)
    at java.awt.EventQueue$1.run(EventQueue.java:603)
    at java.awt.EventQueue$1.run(EventQueue.java:601)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:617)
    at java.awt.EventQueue$2.run(EventQueue.java:615)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Okay, never mind. I got it to work.

commented: Thank you for letting us know that you got it to work. Saves time. +6

Okay, never mind. I got it to work. But I have two other Question.

I want the program to keep the sign in list, it it keeps overwriting itself. how can I stop it from doing that?

Mind if I ask how you fixed it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.