我正在使用 Java Socket 编程。当我第一次单击按钮时,Socket 工作正常。但是按钮和其他功能不再起作用。当我单击它们时,它们都被禁用或没有反应。
这是主要课程
JButton btnRemote = new JButton("Remote ");
btnRemote.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ServerInitiator ser=new ServerInitiator();
ser.initialize(4444);
}
});
套接字类
public static void main(String args[]){
String port = JOptionPane.showInputDialog("Please enter listening port");
new ServerInitiator().initialize(5555);
}
public void initialize(int port){
try {
ServerSocket sc = new ServerSocket(port);
//Show Server GUI
drawGUI();
// drawGUI();
//Listen to server port and accept clients connections
while(true){
Socket client = sc.accept();
System.out.println("New client Connected to the server");
//Per each client create a ClientHandler
new ClientHandler(client,desktop);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}