I've created combobox.. the user have to select from the combo class, subject or grade(A,B,C,D,F)
if the user select class in the text field he should type wich class 7 grade or8grade or 9 grade if he type 7 he should get all of the student name, grade.

how can I do it..

    String [] informationData;
    Information[] info;
    // there is flie linked to java that contain all the information



   String choice = ComboSelect.getSelectedItem().toString();
        String getTxt = txtField.getText();
        txtOutput.setText(" ");

        for (int i = 0; i < info.length; i++) {
            Information temp = info[i];

            if (choice.equals("Class")) {
            //the format method is in another class 
                txtOutput.append(temp.format() + "/n"); 
            }     
        }

How do I test the code you posted?

What is the posted code supposed to do?

Edited 4 Years Ago by NormR1

what I'm trying to do is similar to this
this is the first class
http://assignment0.com/courses/201209/CP3230/examples/studentexample/Student.html
and this is the second class
http://assignment0.com/courses/201209/CP3230/examples/studentexample/StudentForm.html

but in the combo box instide of "Health Scinece , IT ,bussiness enginering" I want
School, Grade and class

aslo I want to add text field box so when the user chose grade from the combo box
he type in the text field if he want to display all the student with grade A,B,C,D or F
and then click display to show the output

Can you make (and post here) a small, complete program that compiles, executes and shows the problem?

Edited 4 Years Ago by NormR1

I just want to add text field to it and dsiplay what in the text field using a format method

Edited 4 Years Ago by sk8ergirl

Please post code you are working on here on the forum. Don't post the whole project. Make a small, complete program that compiles, executes and shows the problem.

student[] students;

public StudentForm() {
    initComponents();

}


private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {                                          

    txtOutput.setText("");

    String[] data = FileUtils.readIntoArray("students.csv");

    students = new Student[data.length];

    for (int i = 0; i < data.length; i++) {
        String line = data[i];
        String[] pieces = line.split(",");
        int sid = Integer.parseInt(pieces[0]);
        String school = pieces[1];
        double gpa = Double.parseDouble(pieces[2]);
        Student temp = new Student(sid, school, gpa);
        students[i] = temp;
    }

    for (int i = 0; i < students.length; i++) {
        Student s = students[i];
        txtOutput.append(s.format() + "\n");
    }


    double avGpa = 0;
    double total = 0;

    for (int i=0; i < students.length; i++) {
        Student temp = students[i];
        total = total + temp.getGpa();
    }
    avGpa = total / students.length;

    txtOutput.append("\n *** Average GPA = " + avGpa);


    comboSchool.setEnabled(true);
    btnDisplay.setEnabled(true);
    btnCreate.setEnabled(false);

}                                         

private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) {                                           
    // TODO add your handling code here:
    String choice = comboSchool.getSelectedItem().toString();
    txtOutput.setText("");
    int count = 0;

    for (int i=0; i<students.length;i++) {
        Student temp = students[i];
        if (choice.equals(temp.getSchool())) {
            txtOutput.append(temp.format() + "\n");
            count++;
        }
    }

    txtOutput.append("\n *** Number of students: " + count);        

}                                          

Edited 4 Years Ago by sk8ergirl

The posted code won't compile without errors. For example there are no import statements and the class definition is missing.

If it doesn't compile, it can't be executed for testing.

The post is obviously copy-and-paste from the original assignment code (look at the OP's link in one of the reply). I think the OP should rephrase the question and ask what he/she should do in order to attach the customized actionPerformed event to a GUI component.

Edited 4 Years Ago by Taywin

This article has been dead for over six months. Start a new discussion instead.