Wednesday, December 4, 2013

Thread not updating boolean array correctly


else

{ if(message.substring(0,4).equals("join"))

{ /* if the first word in the message is "join" then another friend

has joined the message service, retrieve the name of friend

and enable their name button in GUI */


String temp = message.substring(4,message.length());

addOutput("OBSERVE" + temp);

changeFriends(temp, true);


// output message in output area

addOutput(message.substring(4,message.length()) + " has joined the server");

}


Thats the code that adds adds a user to the loggedOn array it does so by calling changeFriends


void changeFriends(String name, boolean b)

{ // change a friend's "online" status


for(int i = 0; i<names.length; i++) //loop through all names

{


if(names[i].equals(name) ) //if a match is found to passed in name

{

loggedOn[i] = true; //store that they are logged on

}

}

// call method to update buttons

isOnline();

}


Thats the method which looks through ausername array for passin username, it then uses the position of the username to set the same position in loggedOn to true



No comments:

Post a Comment