0

After executing the frame created by Swing in the main, we want to display a new frame containing code related to the socket. However, when I do this, the program freezes. Any way?

For example, if I execute the login frame and log in with the administrator ID, I want to create a server socket, and in other cases, I want to create a client socket.

If the source related to the socket is executed directly from the main without going through the frame, communication between the server and the client succeeds.

  • 1
    Your JFrame is freezing because your second code blocks and freezes the Swing event thread or EDT (Event Dispatch Thread), the main Swing thread responsible for drawing the GUI and getting input from users. The solution is to not do this and instead use background threads to avoid blocking this important thread. Please check out [Lesson: Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/). – Hovercraft Full Of Eels Nov 20 '22 at 11:26
  • The specifics of why *your code* is doing this and how to solve the problem specifically for *your code* is impossible to say, since you're not showing it. But look to see if you have any `while (true)` loops or `server.accept()` blocking code or `Thread.sleep(...)` blocking code somewhere. – Hovercraft Full Of Eels Nov 20 '22 at 11:28
  • 1
    In the future (or even now), consider condensing your code and your problem into the smallest program that compiles and runs for us, that demonstrates your problem for us, but that does nothing else, a [mre]. The link will explain exactly what this is and how creating and posting this can help both you and us. You will also want to read the [help] links, especially the [asking](https://stackoverflow.com/help/asking) subsections. Best to do this *before* asking your first question, but better late than never. – Hovercraft Full Of Eels Nov 20 '22 at 11:29
  • Please comment back if you have questions or if you post your [mre] code in your questions so that we can take a look at it. – Hovercraft Full Of Eels Nov 20 '22 at 12:10

0 Answers0