Recieving Messages in Smack

hiiiii Iam new to smack.I created a client in java that connects to gtalk service.I wrote code so that when i get a incoming chat message a private window opens with the paricipant name on it.whenever i get a chat message from the same user,a new window is opening

class control implements ChatManagerListener

{

//basic stuff like connection and login

public void chatCreated(Chat chat, final boolean createdLocally)

{

pm=new pmessage(this,chat);//class that gives private window

}

}

class pmessage implements MessageListener,ActionListener

{

public pmessage(control c,Chat ch)

{

//basic stuff like window creation usung JFrame

MessageListener ml=new MessageListener()

{

public void processMessage(Chat chat, Message message)

{

if(message.getType() == Message.Type.chat)

lstUserList2.addElement(chat.getParticipant() + " says: " + message.getBody());

lstUserList2.addElement("\n");

}

};

ch.addMessageListener(ml);

}

//calls a method sendMessage when the send button is clicked

public void sendMessage(String to,String message) throws XMPPException

{

ch=connection.getChatManager().createChat(to,ml);

ch.sendMessage(message);

}

for each incoming message of the user and my message to the user, new windows are being created.

please help me so that for every user only one window will open and chat goes in that

IAM ATTACHING SCREEN SHOTS OF MY CLIENT

It looks like you are creating a new chat every time you send a message instead of getting the chat that already exists. You should be maintaining a reference to the chats created from your listener and then getting that chat when you want to send a message to the same user.

In addition to that, why is pmessage a MessageListener? This is obviously not complete code so it is hard to determine what might be going on here.