2016-11-18 38 views
-1

我有一個運行基於文本的遊戲的簡單Java程序。用戶將命令輸入到控制檯以便玩遊戲,然後掃描儀讀取輸入。我建立了一個GUI,但我怎麼可以用它來提交用戶輸入的控制檯和執行命令JavaFx GUI用戶輸入

歡呼

+0

使用JavaFX中的文本字段是在[文件]完美的解釋(http://docs.oracle.com/javafx/2 /ui_controls/text-field.htm)。沒有看到你所做的一些嘗試的代碼;我不認爲人們會迴應或知道你想要做什麼。 – px06

回答

0

我想你是編程這樣做(你可以去看一下FXML GUI與SceneBuilder設計因爲它可以讓你的GUI設計過程簡單化,因爲它提供了圖形化的GUI創建)。你有幾個教程和一步一步的例子,將指導你搜索谷歌。您可以按如下程序做到這一點:

final TextField userText = new TextField(); 
somePanel.add(userText); //attach the text field to the scene. 
final Button b = new Button(); 
somePanel.add(b); // attach the button to desired node in the scene 
b.setOnAction(event -> { 
    // Here you call the method with the desired logic, 
    // i suppose you have a text field where the user writes his input, in this case caled userText 
    String text = userText.getText(); 
    // from here you have the text and you are able to use your scanner logic 
}); 

希望這有助於