I have created a simple HTTP server in Java by using a ServerSocket that accepts browser requests. The server is working fine without any errors. I have created a JForm using Swing that contains buttons to start and stop the server. In the start button I have added an ActionListener that runs my ServerMain class.
btnStartServer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
new Thread(new Runnable() {
public void run() {
ServerMain.main(new String[0]);
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
}});
How will I be able to create a Stop JButton which will stop the Runnable() thread?