2016-11-18 124 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 
}); 

希望这有助于