java显示控制台输出到JavaFXML应用程序中的TextArea
我有一个类似“Hello World”的简单程序,它使用getText()
检索两个文本字段的内容并将它们打印到控制台。这个很好用
我定义了一个TextArea,我想显示输出。我已经尝试了我所发现的一切,但我得到了各种各样的错误,因为我试图调整我的代码的答案,所以请原谅我
我真的很感激有人能告诉我你的答案是什么,并解释为什么你的答案有效,因为我正在努力学习
主要方法:-
public class JavaFXApplication2 extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("gui.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}//end start method
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}//end main
}//end class
还有我的控制器
public class guiController implements Initializable {
//@FXML private Label label;
@FXML private TextField tf1;
@FXML private TextField tf2;
@FXML private TextArea ta; //want to display responses here
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("IP Address " + tf1.getText() + " " + "Password: " + tf2.getText());
}//end event handler
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}//end init method
}//end class
简单地说,我希望System.out.println("");
的结果出现在我称为“ta”的文本区域中
谢谢你抽出时间
# 1 楼答案
使用: