Client and GUI concurrently ?

hi everybody,

i got a problem about gui and client. I have created a jframe and i want it to e client which connects to a server and gets the server's message. The problem is; when i created gui first, it starts to listen actions and client can't run, or if i run client class first, it starts to listen server message in a loop on run() method of thread() so action listener can't be catch. The simulation of code is below. Please help me.

public class GUILogin extends JFrame{

public static void main(String args[]) {

new Client("localhost",9999);

new GUILogin().setVisible(true);

}

public class Client implements Runnable{

public Client(String host, int port) {

new Thread(this).start();

}

//LISTENS THE SERVER MESSAGE

public void run() {

String str;

while ((str = readline()) != null) {

System.out.println(str);

}

}

}

I can't decide where to put client creation and gui creation.

[1046 byte] By [ilkayaktasa] at [2007-11-27 9:53:32]
# 1
That's what you get when you overestimate your skills.
-Kayaman-a at 2007-7-13 0:22:47 > top of Java-index,Java Essentials,Java Programming...
# 2

İ think thi solve my problem, thanks much...

public class GUILogin extends JFrame implements Runnable{

public GUILogin {

initializeGUI();

socket = new Socket(host, port);

out = new PrintWriter(socket.getOutputStream(), true);

in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

}

public static void main(String args[]) {

new GUILogin().setVisible(true);

new Thread(this).start();

}

public void run() {

String str;

while ((str = readline()) != null) {

System.out.println(str);

}

}

}

ilkayaktasa at 2007-7-13 0:22:47 > top of Java-index,Java Essentials,Java Programming...