javaFX 布局 控件 设置 背景 图片 java Fx 点击事件 实现跳转页面

看见许多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);
	}
}
  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值