我是java新手。我用一个按钮启动我的服务器
JButton startServerButton = new JButton("Start");
startServerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Start")) {
Runnable serverRunnable = new Runnable() {
public void run() {
runServer();
}
};
Thread serverThread = new Thread(serverRunnable);
serverThread.start();
}
}
});
我想用一个按钮关闭它
JButton endServerButton = new JButton("End");
endServerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("End")) {
closeConnection();
}
}
});
但关闭按钮不起作用......请帮忙!这是关闭功能
private void closeConnection() {
displayMessage("\nTerminating connection\n");
try {
output.close();
input.close();
connection.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}