第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