If I understand your question, there are many ways in which you could do this:
1) In the panel that has the ArrayList, put in a getter method so that the *other* code outside the panel can *get* that ArrayList...
class MyPanel ... {
// stuff
public ArrayList getTheArrayList() {
return theArrayList;
}
}
2) You could create a method in the *other* code that *accepts* an ArrayList, and then pass the ArrayList to that other code, and allow that other code to then populate that ArrayList...
class MyOtherCodeThatFillsArrayList {
pubic void fillArrayList(ArrayList list) {
// do stuff to fill up the ArrayList
// you do not have to return the ArrayList, since you have passed a reference to the
// One True ArrayList, so when the panel uses it again, it is changed.
}
}
If you *have* learned about
polymorphism, then consider making your references of type List instead of an ArrayList, while the actual objects will be of type ArrayList (if you haven't learned about polymorphism yet, do not worry about this yet!!)
There are other issues related to best practices, but there is no need to worry about that right now--I assume that if you are at the beginning level, you are still trying to figure out how all the pieces fit together and work...
cheers,
Kathy