Results 1 to 4 of 4
  1. #1
    rmccleave559 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Thread not updating boolean array correctly

    I have created two programs, one acts a server and the other as a client.I have basically created a chat server program, every time someone new log ins it is validated and then started on a new thread. My problem come sin where there are buttons that are used to communviate with each client(click on it to talk to them). When someone new logs in the array boolean logged in has a value true added to it so if we have four people logged in it shoudl say true, true, true, true.

    The problem is that when someone logs in the array is not being updated in the first client thread so if we have four clients logged in this is what each array returns

    Client 1 logs in : false false false false
    Client 2 logs in : true false false false
    Client 3 logs in : true true false false
    Client 4 logs in : true true true false

    Because the values in client ones thread are all false the buttons to communicate with the other clients are not enabled and will not update when a new client logs in, does anyone have a clue why this happens?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Thread not updating boolean array correctly

    Without an SSCCE, it's going to be pretty much impossible to offer any help.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    rmccleave559 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Re: 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

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,034
    Rep Power
    6

    Default Re: Thread not updating boolean array correctly

    SSCCE = Small, Complete, Correct (Compilable). Yours isn't complete. And please use code tags (see forum guide).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Swing frame not updating correctly
    By Heatryn in forum AWT / Swing
    Replies: 2
    Last Post: 07-05-2012, 05:24 PM
  2. Replies: 2
    Last Post: 05-21-2012, 11:59 AM
  3. Code completion not updating correctly
    By kspn in forum NetBeans
    Replies: 1
    Last Post: 02-22-2011, 11:28 PM
  4. Did I do this THREAD correctly?
    By TimHuey in forum New To Java
    Replies: 4
    Last Post: 04-24-2010, 06:54 AM
  5. Updating a SWT progress bar from another thread
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •