我正在尝试编写一个代码JButton,当我单击它时,文本将从“连接”更改为“断开连接”,但是 Eclipse 给我一个错误,提示“无法解析连接”。我也尝试过将其放在 try catch 循环之外。
btnConnect = new JButton("Connect");
btnConnect.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent arg0) {
try {
Connect.setText("Disconnect");
int portNum = 5520;
String hostAddress = Actual_IP_Address.getText();
sock = new Socket(hostAddress, portNum);
writeSock = new PrintWriter ( sock.getOutputStream(), true);
readSock = new BufferedReader (new InputStreamReader(sock.getInputStream()));
}
catch(Exception ex) {
System.out.println("Error: " + ex);
sock = null;
}
}}
);
任何指示将不胜感激。
冉冉说
相关分类