JavaFX |轻。点类

光Point类是JavaFX的一部分。光Point类表示三维空间中的点光源。光Point类扩展了Light类。

null

类的构造函数:

  1. 第()点 :使用默认值创建新的点光源对象。
  2. 点(双x,双y,双z,彩色) :使用x、y、z和颜色值创建新的点光源对象。

常用方法:

方法 解释
getX() 返回x的值。
getY() 返回y的值。
getZ() 返回z的值。
setX(双v) 设置x的值。
赛蒂(双v) 设置y的值。
setZ(双v) 设置z的值。
getColor() 返回灯光的颜色。
设置颜色(颜色v) 设置灯光的颜色。

下面的程序说明了光线的使用。积分等级:

  1. 创建点光源并将其添加到矩形的Java程序: 在这个程序中,我们将创建一个名为 长方形 具有指定的高度和宽度。我们还将创建一个灯光。点对象命名为 .我们将使用 setX() , 塞蒂() setZ() 作用现在创建一个照明对象,并使用 setLight() 作用我们将为矩形设置灯光效果,并将其添加到场景中,将场景添加到舞台中,然后调用show函数来显示结果。

    // Java Program to create a Point light
    // and add it to a rectangle
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.control.*;
    import javafx.stage.Stage;
    import javafx.scene.Group;
    import javafx.scene.effect.Light.*;
    import javafx.scene.effect.*;
    import javafx.scene.paint.Color;
    public class Point_1 extends Application {
    // launch the application
    public void start(Stage stage)
    {
    // set title for the stage
    stage.setTitle( "creating Light.Point" );
    // create point Light object
    Light.Point light = new Light.Point();
    // set coordinates
    light.setX( 100 );
    light.setY( 100 );
    light.setZ( 100 );
    // create a lighting
    Lighting lighting = new Lighting();
    // set Light of lighting
    lighting.setLight(light);
    // create a rectangle
    Rectangle rect = new Rectangle( 250 , 250 );
    // set fill
    rect.setFill(Color.WHITE);
    // set effect
    rect.setEffect(lighting);
    // create a Group
    Group group = new Group(rect);
    // create a scene
    Scene scene = new Scene(group, 500 , 300 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输出:

    图片[1]-JavaFX |轻。点类-yiteyi-C++库

  2. Java程序创建一个点光源,并将其添加到矩形中,然后将光源的颜色设置为红色: 在这个程序中,我们将创建一个名为 长方形 具有指定的高度和宽度。我们还将创建一个灯光。点对象命名为 .现在将x、y、z和颜色值作为构造函数的参数传递。我们将创建一个照明对象,并使用 setLight() 作用我们将为矩形设置灯光效果,并将其添加到场景中,将场景添加到舞台中,然后调用show函数来显示结果。

    // Java Program to create a Point light and add it to
    // a rectangle and set the color of the light to red
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.control.*;
    import javafx.stage.Stage;
    import javafx.scene.Group;
    import javafx.scene.effect.Light.*;
    import javafx.scene.effect.*;
    import javafx.scene.paint.Color;
    public class Point_2 extends Application {
    // launch the application
    public void start(Stage stage)
    {
    // set title for the stage
    stage.setTitle( "creating Light.Point" );
    // create point Light object
    Light.Point light = new Light.Point( 100 , 100 ,
    100 , Color.RED);
    // create a lighting
    Lighting lighting = new Lighting();
    // set Light of lighting
    lighting.setLight(light);
    // create a rectangle
    Rectangle rect = new Rectangle( 250 , 250 );
    // set fill
    rect.setFill(Color.WHITE);
    // set effect
    rect.setEffect(lighting);
    // create a Group
    Group group = new Group(rect);
    // create a scene
    Scene scene = new Scene(group, 500 , 300 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输出:

    图片[2]-JavaFX |轻。点类-yiteyi-C++库

注: 上述程序可能无法在联机IDE中运行。请使用脱机编译器。

参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Light.Point.html

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享