反射类是JavaFX的一部分。反射类用于在输入值的实际图像下方添加反射图像。反射的图像不会响应鼠标事件或输入上的控制方法。
null
类的构造函数:
- 反思() :创建一个新的反射对象。
- 反射(双地形偏移、双分数、双地形容量、双底部不透明度) :使用指定的地形偏移、分数、地形容量和底部不透明度创建新的反射对象。
常用方法:
方法 | 解释 |
---|---|
getBottomOpacity() | 返回bottomOpacity的值 |
GetToPoacity() | 返回TopoCapacity的值 |
getFraction() | 返回反射图像与真实图像的比例 |
GetToOffset() | 返回顶部偏移量的值 |
getInput() | 返回属性输入的值 |
减容能力(双v) | 设置底部不透明度的值 |
设置容量(双v) | 设置拓扑容量的值 |
设定分数(双v) | 设置反射图像与真实图像的比例 |
SetToOffset(双v) | 设置“顶部偏移”的值 |
设置输入(效果v) | 设置属性输入的值 |
下面的程序说明了反射类的使用:
- 使用reflection类向图像添加反射的Java程序: 在这个节目中 文件输入流类 创建并从文件中获取图像作为输入。一幅名为 形象 使用文件输入流中的输入创建。从图片上看,一个 图像视图对象 创建并将其添加到 VBox 。然后将VBox添加到场景,并将场景添加到舞台。将创建反射效果,并使用将该效果设置为图像视图 setEffect() 作用
// Java program to add a reflection to
// the image using the reflection class
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.control.*;
import
javafx.scene.layout.*;
import
javafx.stage.Stage;
import
javafx.scene.image.*;
import
javafx.scene.effect.*;
import
java.io.*;
import
javafx.event.ActionEvent;
import
javafx.event.EventHandler;
import
javafx.scene.Group;
public
class
reflection_1
extends
Application {
// launch the application
public
void
start(Stage stage)
throws
Exception
{
// set title for the stage
stage.setTitle(
"reflection example"
);
// create a input stream
FileInputStream input =
new
FileInputStream(
"D:\GFG.png"
);
// create a image
Image image =
new
Image(input);
// create a image View
ImageView imageview =
new
ImageView(image);
// create a reflection effect
Reflection reflection =
new
Reflection();
// set effect
imageview.setEffect(reflection);
// create a VBox
VBox vbox =
new
VBox(imageview);
// create a scene
Scene scene =
new
Scene(vbox,
200
,
200
);
// set the scene
stage.setScene(scene);
stage.show();
}
// Main Method
public
static
void
main(String args[])
{
// launch the application
launch(args);
}
}
输出:
- Java程序使用reflection类向图像添加反射,并设置 顶部偏移、顶部不透明度、底部不透明度和分数 将显示为反射的图像: 在这个程序中,创建一个FileInputStream,并从文件中获取一个图像作为输入。图像名为 形象 使用文件输入流中的输入创建。从图片上看,一个 图像视图对象 创建并将其添加到 VBox 这个 VBox 然后被添加到场景中,场景被添加到舞台上。将创建反射效果,并使用将该效果设置为图像视图 setEffect() 作用这个 底部不透明度、顶部不透明度、顶部偏移和分数 使用 SetBottoMoCapacity()、SetTopoCapacity()、setFraction()和SetTopoOffset() 分别起作用。
// Java program to add a reflection to the image
// using the reflection class and set the top
// offset, top opacity bottom opacity and fraction
// of image which will appear as reflection
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.control.*;
import
javafx.scene.layout.*;
import
javafx.stage.Stage;
import
javafx.scene.image.*;
import
javafx.scene.effect.*;
import
java.io.*;
import
javafx.event.ActionEvent;
import
javafx.event.EventHandler;
import
javafx.scene.Group;
public
class
reflection_2
extends
Application {
// launch the application
public
void
start(Stage stage)
throws
Exception
{
// set title for the stage
stage.setTitle(
"reflection example"
);
// create a input stream
FileInputStream input =
new
FileInputStream(
"D:\GFG.png"
);
// create a image
Image image =
new
Image(input);
// create a image View
ImageView imageview =
new
ImageView(image);
// create a reflection effect
Reflection reflection =
new
Reflection();
// set fraction
reflection.setFraction(
0.6
);
// set top Opacity
reflection.setTopOpacity(
0.3
);
// set bottom Opacity
reflection.setBottomOpacity(
0.1
);
// set top offset
reflection.setTopOffset(
0.5
);
// set effect
imageview.setEffect(reflection);
// create a VBox
VBox vbox =
new
VBox(imageview);
// create a scene
Scene scene =
new
Scene(vbox,
200
,
200
);
// 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/Reflection.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END