我真的很困惑:当我在eclipse中正常运行我的程序时,我的一些代码无法正常工作,但是当我使用调试模式单独运行每个步骤时,它确实工作了.
码:
public void showConnectDialog() {
ConnectDialog connectDialog = new ConnectDialog();
connectDialog.setVisible(true);
//Until here, code runs
while(! connectDialog.getConnected()) {};
//The next line does only run in debug
JOptionPane.showMessageDialog(connectDialog, "Connected", "Connected", JOptionPane.INFORMATION_MESSAGE);
}
Run Code Online (Sandbox Code Playgroud)
连接器(一旦用户在对话框中点击"连接")就启动(作为线程):
private class ServerConnector implements ActionListener, Runnable {
@Override
public void actionPerformed(ActionEvent e) {
if (! IP_field.getText().equals("")) {
if (! isConnecting) {
new Thread(new ServerConnector(), "ServerConnector").start();
}
}
else {
JOptionPane.showMessageDialog(dialog,
"Enter an IP address",
"Enter IP",
JOptionPane.WARNING_MESSAGE);
}
}
@Override
public void run() {
try {
setConnecting(true); …Run Code Online (Sandbox Code Playgroud)