Reputation: 1
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();
}
}
}
The code in bold doesn't work. When I added breakpoints to check whether the compiler is going inside IF then it was not. Please explain me why IF condition is not running.
Upvotes: 0
Views: 34
Reputation: 10511
Your possible selection values are "Server "
and " Client"
but you compare to "Server"
and "Client"
. The strings are not equal because of the leading/trailing spaces.
Upvotes: 2