How to in a class, use an attribute of a different class to find out the other attribute. (java)
<p>Sorry if i'm being vague here, i'll post my code for you guys too. I'm a beginner so go easy on me.</p>

<p>I have a class called student, it has an int id, and another String name. I have created another Class for the GUI. It has a window that pops up and has a field for the id. I want to enter the ID and get the Name from that ID. I have no idea of going about this and i've been stuck for hours. I'm kind of slow to catch on, so could someone help me? I'm not very good at inheritance. (also, i have two other classes, but i don't think they would be of any help here.</p>

<p>STUDENT CLASS</p>

<pre><code>public class Student {
    private int id;
    private String name;
    private ArrayList&lt;Course&gt; regCourses;

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public ArrayList&lt;Course&gt; getRegCourses() {
        return regCourses;
    }

    public Student(int i, String n) {
        id = i;
        name = n;
        regCourses = new ArrayList&lt;Course&gt;();
    }

    public String toString() {
        String answer = id + " " + name + " - Registered Courses: ";
        if (regCourses.size() == 0)
            answer += "NONE";
        else {
            for (int i = 0; i &lt; regCourses.size(); i++) {
                answer += regCourses.get(i).getDepartment().getId()
                        + regCourses.get(i).getCode();
                if (i != regCourses.size() - 1)
                    answer += ", ";
            }
        }
        return answer;
    }

    public void registerFor(Course c) {
        if (!isRegisteredInCourse(c)) {
            // Register
            regCourses.add(c);
            if (!c.getClassList().contains(this)) {
                c.getClassList().add(this);
                if (!c.getDepartment().getStudentList().contains(this))
                    c.getDepartment().getStudentList().add(this);
            }
        }
    }

    public boolean isRegisteredInCourse(Course c) {
        return regCourses.contains(c);
    }
}
</code></pre>

<p>And here's the search code in another class.</p>

<pre><code>public class MainGUIWindow extends JFrame implements ActionListener {
    JLabel studentID, studentName, currentRegCourses;
    JButton search, regForCourse, withdraw;
    JTextField idField, nameField;
    JScrollPane courseScrollList;

    public MainGUIWindow(String title) {
        super(title);

        //GUI STUFF
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == search) {
            if (idField.getText() != null) {
                int id = Integer.parseInt(idField.getText());
                Student temp = null;
                                //CODE GOES HERE

            }
        }
    }

    public static void main(String[] args) {
        new MainGUIWindow("Student Administration System").setVisible(true);
</code></pre>

<p>Also, if need be, these all my java files.
<a href="http://www.filehosting.org/file/details/426633/JavaCode-SO.zip" rel="nofollow">http://www.filehosting.org/file/details/426633/JavaCode-SO.zip</a></p>

<p>Edit: There are 2 more Classes that are my test programs that have data in them.</p>
