addAll() 方法不起作用?
addAll() method not working?
所以也许我没有按照预期的方式使用它,但我在 youtube 用户 thenewboston 观看的视频中使用了它,并且效果很好。帮助将不胜感激
package checkers;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import javafx.scene.Scene ;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.application.*;
import javafx.stage.*;
public class Checkers extends Application {
Stage window;
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Title");
HBox layout = new HBox();
Button startButton = new Button("Start");
Button quitButton = new Button("Quit");
layout.getChildren().addAll(startButton, quitButton);
Scene startScene = new Scene(layout, 400, 300);
window.setScene(startScene);
window.show();
}
public static void main(String[] args) {
launch(args);
}
}
`
我收到的错误如下 -
"The method addAll(int, Collection) in the type List is not applicable for the arguments (Button, Button)"
您导入了错误类型的 Button
。你想要 import javafx.scene.control.Button;
而不是 import java.awt.Button;
所以也许我没有按照预期的方式使用它,但我在 youtube 用户 thenewboston 观看的视频中使用了它,并且效果很好。帮助将不胜感激
package checkers;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import javafx.scene.Scene ;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.application.*;
import javafx.stage.*;
public class Checkers extends Application {
Stage window;
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Title");
HBox layout = new HBox();
Button startButton = new Button("Start");
Button quitButton = new Button("Quit");
layout.getChildren().addAll(startButton, quitButton);
Scene startScene = new Scene(layout, 400, 300);
window.setScene(startScene);
window.show();
}
public static void main(String[] args) {
launch(args);
}
}
`
我收到的错误如下 - "The method addAll(int, Collection) in the type List is not applicable for the arguments (Button, Button)"
您导入了错误类型的 Button
。你想要 import javafx.scene.control.Button;
而不是 import java.awt.Button;