Java 如何以新形式导入4张图像
我是JavaFX新手,这是我的代码。此应用程序有一个按钮,如果单击该按钮将打开新表单。有人知道如何在新表单中插入4张图片吗Java 如何以新形式导入4张图像,java,eclipse,javafx,Java,Eclipse,Javafx,我是JavaFX新手,这是我的代码。此应用程序有一个按钮,如果单击该按钮将打开新表单。有人知道如何在新表单中插入4张图片吗 package javafxwindow; import javafx.application.Application; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.control.Bu
package javafxwindow;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
我使用的软件包。类JavaFXWindow
public class JavaFXWindow extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Open a New Window");
btn.setOnAction((ActionEvent event) -> {
Label secondLabel = new Label("Hello");
StackPane secondaryLayout = new StackPane();
secondaryLayout.getChildren().add(secondLabel);
Scene secondScene = new Scene(secondaryLayout, 200, 100);
Stage secondStage = new Stage();
secondStage.setTitle("New Stage");
secondStage.setScene(secondScene);
secondStage.show();
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("java-buddy.blogspot.com");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setOnCloseRequest(e -> Platform.exit());
}
public static void main(String[] args) {
launch(args);
}
}
创建VBox root2=新建VBox();然后创建四个ImageView。将每个图像添加到ImageView将ImageView添加到root2将root 2添加到新场景将新场景添加到secondStage。与您创建primaryStage时所做的非常相似。我不喜欢这种类型的编程。我建议您学习模型视图控制。这将允许您使用诸如SceneBuilder之类的应用程序来构建视图。然后您只需专注于您的逻辑。
StackPane secondaryLayout=newstackpane(imageView1、imageView2、imageView3、imageView4)代码>这会根据问题描述执行您正在尝试执行的操作,但是图像会彼此重叠。。。但是,由于您没有指定任何其他关于图像添加方式的信息,这似乎解决了您的问题,对吧???