I have been working on the following code:
public class MyStuff {
public static void main(String[] args)throws IOException {
//System.out.println("From Test");
ControlGack gack = new ControlGack();
gack.setVisible(true);
MainWindow mW = new MainWindow();
mW.run(null);
Client c = new Client();
try {
c.run(null);
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("Stupid");
}
}
The MainWindow has a while loop that just repeats while the program is running. How do I start the Client class and run it simultaneously with the rest of the program?
A few options…
MainWindowin a separateThreadClientas a separate Java applicationUsing a new Thread should be a pretty easy fix – something like this…
Or, better yet, change your
MainWindowclass toextends Threadorimplements Runnable. If you do that, you can simply execute it by callingmW.start();instead of your currentmW.run(null);method,l and it will kick it off in a separateThreadfor you.Refer to the Thread and Runnable documentation for more information.