2017-06-08 142 views
1

我正在开发一个用于国际象棋的小型服务器 - 客户端系统。用户可以要求其他用户进行游戏,这是我的问题。客户端向服务器发送消息,服务器将消息直接发送给另一个客户端,另一个客户端获取消息。在收到消息后,客户应该打开一个警报来选择是否要与其他客户端玩,但它不会打开。这是我的代码JavaFX 8 - 警报未打开

} else if (readed.equals("+anfrage")){ 
    String n=clientSocket.readLine(); 
    Alert in=new Alert(AlertType.CONFIRMATION);  //here the program stucks 
    in.setHeaderText("Spielanfrage von: "+n); 
    in.getButtonTypes().clear(); 
    in.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); 
    in.setResizable(false); 
    Optional<ButtonType> opt=in.showAndWait(); 
    if (opt.get()==ButtonType.YES) { 

    } else{ 

    } 

回答

0
Alert alert = new Alert(AlertType.CONFIRMATION, " Your Message" + selection + " ?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); 
alert.showAndWait(); 

if (alert.getResult() == ButtonType.YES) { 
    //do stuff 
}else{ 
    //do other stuffs 
}