第14章 JavaFx基础

第14章 JavaFx基础

JavaFx、 方法、 对象和类、 面对对象思考、 继承和多态

14-1:

//主要为基本javafx语法
//Main.java
package application;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Main extends Application
{
   	
	@Override//Overide the start method in the applicaton class
	public void start (Stage primaryStage) 
	{
   
	//Create a scene and place a buttton in the scene 
		Button btOK=new Button("OK");
		
		Scene scene=new Scene(btOK);//不给Scene赋值大小(默认值):
		/* 如要设置大小:
		Scene scene=new Scene(btOK,200,250);  //设置为200*250个像素大小
		*/
		primaryStage.setTitle("MyJavaFX");  //set the scene title 
		primaryStage.setScene(scene);  //place the scene in the stage 
		primaryStage.show();  // display the stage 
	} 
	/*the main method is only needed for the IDE with limited 
	 *javafx support.   not needed for runing from the command line.
	 */
	public static void main(String[] args) 
	{
   
	Application.launch(args);	
	}
}

运行效果截图(默认值):

在这里插入图片描述

注意:默认的就这么一个小图:

自动适应大小的

注意:不是没有setTitle()的喏,界面框太小了,没显示到,而不是没设置或者设置失败。

拉长后的图:
在这里插入图片描述

设置大小的展示效果:

假设设置为200*250个像素大小:

注意看该图设置的大小

在这里插入图片描述

就这个样子

在这里插入图片描述

或者这个样子(注意大小):

在这里插入图片描述
划基本重点:所以设置的是长乘高喏(或者行长乘以列长 )(row*column)
Scene对象的构造方法:

为 Scene(node,width,height);

在这里插入图片描述

14-2

package application;
//以下皆省略//Main.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Main extends Application
{
   	//Overide the start method in the applicaton class
	public void start (Stage primaryStage) 
	{
   
		//Create a scene and place a buttton in the scene 
		Scene scene=new Scene(new Button("OK"),250,200);
		
		primaryStage.setTitle("MySecondJavaFX");
		primaryStage.setScene(scene);
		primaryStage.show();
		
		Stage stage=new Stage();  //set a stage with a button in the stage 
		stage.setTitle("Second Stage");		     
		stage.setScene(new Scene(new Button("New Stage"),250,200));
		stage.show();
	}
	public static void main(String[] args) 
	{
   
	App
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

美迪的麦柯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值