0
public class ClientServer {
public static void main (String[] args){
Object[] selectioValues = {"Server "," Client"};
String initialSection = "Server";
Object selection = JOptionPane.showInputDialog(null,"login As:","Client server", JOptionPane.QUESTION_MESSAGE,null , selectioValues , initialSection);
**if(selection.equals("Server"))**{
server srv = new server();
srv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
srv.startRunning();
}
**else if (selection.equals("Client"))**{
String IPServer = JOptionPane.showInputDialog("enter IP:");
Client capsa;
capsa = new Client(IPServer);
capsa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
capsa.startRunning();
}
}
}
粗体代码不起作用。当我添加断点来检查编译器是否进入IF内部时,它不是。请解释为什么IF条件不运行。与字符串值的对象值比较不会发生
编译器不会执行您的代码。 “选择”不能等于“服务器”。 – 2015-04-03 17:09:14
我重新检查了我的代码.selection的值是“Server”。我没有找到尾部空格 – Snakeeyes 2015-04-04 05:53:34