看见许多JavaFx 发现讲的很啰嗦,帮助还不大,希望写下这些的对您们有帮助
页面1
package aaa;
import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class aa extends Application{
BorderPane borderPane = new BorderPane();
@Override
public void start(Stage primaryStage) throws Exception {
Button b1 = new Button("aaaaaaaaaa");
//增加
b1.setOnAction(a->{
//打开新增Add页面
try {
//Add构造方法需要一个首页对象
// 直接new Start 页面 有参数 放参数
new bb().start(new Stage());
} catch (Exception e) {
e.printStackTrace();
}
});
borderPane.setTop(b1);
// 绝对路径
Image input = new Image("file:G:\\美女.jpg",600,300,false,false);
// background-image 为元素设置背景图像。
BackgroundImage backgroundimage = new BackgroundImage(input,
BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT,
BackgroundPosition.DEFAULT,
BackgroundSize.DEFAULT);
// 放进去
Background background = new Background(backgroundimage);
//把图片放布局里面
borderPane.setBackground(background);
// 绑定布局和场景
Scene scene = new Scene(borderPane, 600, 300);
primaryStage.setScene(scene);// 显示舞台
// 控件添加图片
String file = new String("/img/1.jpg");
primaryStage.getIcons().add(new Image(file, 600, 400, true, true));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
页面跳转在这里
package aaa;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class bb extends Application{
BorderPane borderPane = new BorderPane();
Button b1 = new Button("bbbbbbbbbbbb");
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(borderPane, 300, 300));
borderPane.setTop(b1);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}