• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

GUI hangs on socket loop

I'm writing a server wich can be started using a gui. When I click on a button to start my server, the gui hangs. I tried to solve it by creating 2 threads, one for the gui, and one for the server, but still no change. How can I solve this ?

Some code:

public class RiotServerGUI extends javax.swing.JFrame {
   
    private RiotServer server;
    private Thread serverThread;
    private Thread guiThread;
   
    public RiotServerGUI() {
       
        serverThread = new Thread(new Runnable() {
                public void run() {
                    server = new RiotServer();
                    server.startServer();
                }
                public void stop() {
                    server.stopServer();
                }
        });
       
        guiThread = new Thread(new Runnable() {
            public void run() {
                initComponents();
            }
        });
       
        guiThread.run(); // Run gui
       
    }

...

private void tglConnectActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        if (tglConnect.isSelected()) {
            tglConnect.setLabel("Disconnect");
            // Start serverthread.
            serverThread.run();
        } else {
            tglConnect.setLabel("Connect");
            serverThread.stop();
        }
       
    }  
0
Reggie_BE
Asked:
Reggie_BE
  • 2
1 Solution
 
Nick_72Commented:
What if you call start() instead of run() ?

/Nick
0
 
Reggie_BEAuthor Commented:
OMG, that's all ?
Ok thnx :)
0
 
Nick_72Commented:
Don't know if it solves all but even though the method is called run() the thread should be started with a call to start() :)

/Nick
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now