我的代码:
public class Main extends Application {
TextArea area = new TextArea();
TextField field = new TextField();
String text = "";
public void start(Stage primaryStage){
VBox pane = new VBox();
Button next = new Button("Next");
next.setOnAction(e->{
text+= "n" + field.getText();
area.setText(text);
});
pane.getChildren().addAll(area,field,next);
Scene scene = new Scene(pane, 700, 300);
primaryStage.setTitle("CosmicWimpout");
primaryStage.setScene(scene);
primaryStage.show();
}
错误在.addAll
上,错误读数为:
The method addAll(int, Collection<? extends Node>) in the type List<Node> is not applicable for the arguments (TextArea, TextField, String).
所以我只是编辑了我的帖子,包括.addAll(区域,字段,下一个)。这些都是GUI节点,但是.addAll方法不接受这些参数。
正如@sillyfly已经指出的,pane
是VBox
类型,它是Parent
的一个子类型。方法getChildren
将返回类型为Node
的ObservableList
。因此,子列表上的方法addAll
将采用类型为Node
的var arg作为参数。String
显然不是Node
类型。
您要导入哪些类?对我来说,当我导入时发生了错误:
import java.awt.Label;
而不是:
import javafx.scene.control.Label;
当IDE自动为您导入类时,通常会发生这种情况。有时您应该考虑手动输入它们。