光Point类是JavaFX的一部分。光Point类表示三维空间中的点光源。光Point类扩展了Light类。
null
类的构造函数:
- 第()点 :使用默认值创建新的点光源对象。
- 点(双x,双y,双z,彩色) :使用x、y、z和颜色值创建新的点光源对象。
常用方法:
方法 | 解释 |
---|---|
getX() | 返回x的值。 |
getY() | 返回y的值。 |
getZ() | 返回z的值。 |
setX(双v) | 设置x的值。 |
赛蒂(双v) | 设置y的值。 |
setZ(双v) | 设置z的值。 |
getColor() | 返回灯光的颜色。 |
设置颜色(颜色v) | 设置灯光的颜色。 |
下面的程序说明了光线的使用。积分等级:
- 创建点光源并将其添加到矩形的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);
}
}
输出:
- 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);
}
}
输出:
注: 上述程序可能无法在联机IDE中运行。请使用脱机编译器。
参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Light.Point.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END