无法解析 JButton 变量
JButton variable cannot be resolved
我正在尝试编写 JButton
代码,当我单击它时,文本将从“连接”变为“断开连接”,但是 Eclipse 给我一个错误,提示 "Connect cannot be resolved." 我已尝试将其放在外面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;
}
}}
);
任何指点将不胜感激。
将 Connect.setText("Disconnect");
更改为 btnConnect.setText("Disconnect");
。
Connect
是不存在的 class,这就是 Eclipse 向您发出警告的原因。
我正在尝试编写 JButton
代码,当我单击它时,文本将从“连接”变为“断开连接”,但是 Eclipse 给我一个错误,提示 "Connect cannot be resolved." 我已尝试将其放在外面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;
}
}}
);
任何指点将不胜感激。
将 Connect.setText("Disconnect");
更改为 btnConnect.setText("Disconnect");
。
Connect
是不存在的 class,这就是 Eclipse 向您发出警告的原因。