Link to home
Start Free TrialLog in
Avatar of Reggie_BE
Reggie_BE

asked on

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();
        }
       
    }  
ASKER CERTIFIED SOLUTION
Avatar of Nick_72
Nick_72

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Reggie_BE
Reggie_BE

ASKER

OMG, that's all ?
Ok thnx :)
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