0

I am making an IM chat client and need to use one randomly generated session ID for 3 classes but can't get it to work. When I try to pass it from one to the other it just makes a new one. The idea is that classA runs the chat and creates a new folder named after the sessionID, and saves the chatLog there. classB opens the folder (which is why it needs to know the sessionID) and runs methods on the data within the folder. Any help is appreciated.

cHam
  • 2,624
  • 7
  • 26
  • 28

1 Answers1

0

Make the sessionID a class of it's own.

In constructor of class A

then when you go to call class B, add it in the constructor

B item = new B(id);

for B

sessionID session;
Public B (SessionID myid)
{
    session = myid;
    // add extra code
}

then use session as your session id.

Edit:

class A
{
    public A ()
    {
        sessionID id = new sessionID();
    }
Thread mychat = new B(id);
mychat.start();
}

class B extends Thread  
{
    // make constructor
    Public B (SessionID myid)
    {
            session = myid;
    }
    // This method is called when the thread runs
    public void run() 
    {
        //working code
    }
}

I cannot make it any clearer then that.. sorry if you still don't understand it.

Matt Westlake
  • 3,499
  • 7
  • 39
  • 80
  • The problem is that when I do that the program slows to a stop until the method in class B has finished. how could I call a classB method and have classA continue without waitng for the method from classB to finish? – cHam Jul 10 '12 at 14:33
  • spawn it in a new thread. Are you fermiliar with multi-threading at all? Here is a great tutorial. http://www.exampledepot.com/egs/java.lang/basicthread.html – Matt Westlake Jul 10 '12 at 14:36
  • I have never used threading, not sure how I would use that even after reading the tutorial. I'm fairly new to java. – cHam Jul 10 '12 at 14:49
  • @cHam I updated my code to give you the best explination (an example) I can. If you still don't understand, I'm sorry but that is about all I can do. If you have specific questions, still feel free to ask – Matt Westlake Jul 10 '12 at 14:58