Quote
......to be able to use a viewPicture method to see another persons picture, how can this be done?
Examine this class:
public class Human {
int age;
String dob;
char sex;
public Human(int age, String dob, char sex)
{
this.age = age;
this.dob = dob;
this.sex = sex;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
public static void main(String args[])
{
ArrayList <Human> list = new ArrayList<Human>();
Human fread = new Human(22,"1-1-2011",'M');
Human qutazs = new Human(21,"1-2-2011",'F');
list.add(fread);
list.add(qutazs);
}
}
As you can see there are two handles fread an qutazs. Each handle has access to its own of variables and methods. Now although these handles have a similar set of variables and methods, they do not have access to each others data.
When you say:
qutazs.mutator();
qutazs.accessor();
you only get access to your copy of the data. You cannot directly access minds, unless you make your handle equal to minds.
Doing something like this:
qutazs = fread;
will give you direct access to my copy of the data; unfortunately at the price of you own(unless you use a temp Human variable to hold your handle, then restore).
If you wish to view data from similar objects you will need to walk through the objects in question and request whatever you need.
Think of the mess you would have if you were able to just access my data.
You can access all the data of these objects my calling them individually like this:
for(int i = 0; i < list.size(); i++)
System.out.println(list.get(i).getAge());
As for:
person2.receiveMessage(msg); // This is the real problem atm.. I don't know what I should wrote instead of 'msg'
Try:
person2.receiveMessage(new Message(person2.getName(), "msg"));
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused: