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条件没有运行。
答案 0 :(得分:2)
您的可能选择值为"Server "
和" Client"
,但您要与"Server"
和"Client"
进行比较。由于前导/尾随空格,字符串不相等。