I am trying to create a chat client for a program of mine and I would like to open a new window for each chat (A & B will not be in the same window as A & C) I have psudocode for what I am trying to do but unsure on how to write it.
Chat client:
inputstream.read()
Read who message from
If (chat window arleady open with person from)
{
Add Message to output section of the window
{
else if (chat window not open)
{
Open new chat window with person from
Display message in new chat window
}
To do this, the thing I have thought about is storing the IPs in an array and then whenever the client gets a message it would look through the array to see if the IP was stored. If it is stored, the window should already be open, otherwise the window needs to be opened. I can program this by using the defaultonclose command from JFrame to just call a removal of the IP when the window is closed, but here are the problems I am running into.
- Once I search the array for the IP addresses, If the window is already open (say I have A B and C talking to D) how do I insure if C sends a message that it gets placed in the C window?
1.1 I have thought about spawning a new thread, naming the thread, and then when a message comes in pass it into the the thread that matches the name, but I am not sure about how to do that. I have read the names of threads before but never passed something into a specific thread.
Is there anyway to do this easier without downloading extra libs?
don’t use
JFramefor another window, because you can’t to setparent v.s.owner, useJDialoginsteadthen
JFrame.getOwnedWindows()returns all instances ofJDialog(s)where is used JDialog(myFrame owner)in all cases
Window[] allWindows = Window.getWindows();returns all instances from current JVM, returns all instances of(J)Frames,(J)Dialogs,(J)WindowsorJOptionsPanes