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.e vent.Actio nEvent evt) {
// TODO add your handling code here:
if (tglConnect.isSelected()) {
tglConnect.setLabel("Disco nnect");
// Start serverthread.
serverThread.run();
} else {
tglConnect.setLabel("Conne ct");
serverThread.stop();
}
}
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(
// TODO add your handling code here:
if (tglConnect.isSelected()) {
tglConnect.setLabel("Disco
// Start serverthread.
serverThread.run();
} else {
tglConnect.setLabel("Conne
serverThread.stop();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
/Nick
ASKER
Ok thnx :)