powered by Jive Software

Creating multiple chat instances

Hi everyone,

I’m creating a Java IM application (not a web applet) and i’m using the Smack API which so far has been brilliant.

The only problem I am having is that I want to be able to click on a user and open a chat with that user. I can do this but only for one user. EG: If I close the chat window, click on another user and message them, it still goes to the first user.

I know what is happening and I kinda know what my problem is but I don’t know a way around it! How can I get the application to dynamically create new instances of my chatBox class for each user? Perhaps this is the wrong way to go about it… i’m not sure.

Please see my code below:

private void chatButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                   int selectedUserIndex = rosterList.getSelectedIndex();         String selectedUser = rostAry[selectedUserIndex].getUser();
        System.out.println("Chat with: " + selectedUser);         if (chatBox == null) {
            JFrame mainFrame = CommsTestApp.getApplication().getMainFrame();
            chatBox = new CommsTestChatBox(mainFrame,conn,selectedUser);

So in summary, instead of creating one instance of chatBox called chat, I want to create a new chat instance for each user with a name like chatBoxUser1 or chatBoxUser2. How can this be done?

Thanks in advance


I made an array to hold a chat instance for each user in the Roster

Stored the valeus in an Array