Javafx-reflection-effect
提供:Dev Guides
JavaFXエフェクト-リフレクション
JavaFXのノードに反射効果を適用すると、ノードの下部に反射が追加されます。
パッケージ javafx.scene.effect の Reflection という名前のクラスは、反射効果を表します。 このクラスには4つのプロパティが含まれています-
- topOpacity -このプロパティは、反射の最上部の不透明度の値を表すdouble型です。
- bottomOpacity -このプロパティは、反射の最下部の不透明度値を表すdouble型です。
- input -このプロパティはEffect型であり、反射効果への入力を表します。
- topOffset -このプロパティは、入力の下部と反射の上部との間の距離を表すdouble型です。
- fraction -このプロパティは、出力に表示される入力の割合を表すdouble型です。 小数値の範囲は0.0〜1.0です。
例
次のプログラムは、反射効果を示す例です。 ここでは、DARKSEAGREENカラーで塗りつぶされたテキスト「Welcome to finddevguides」を描画し、それに反射効果を適用しています。
このコードを ReflectionEffectExample.java という名前のファイルに保存します。
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Reflection;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class ReflectionEffectExample extends Application {
@Override
public void start(Stage stage) {
//Creating a Text object
Text text = new Text();
//Setting font to the text
text.setFont(Font.font(null, FontWeight.BOLD, 40));
//setting the position of the text
text.setX(60);
text.setY(150);
//Setting the text to be embedded.
text.setText("Welcome to finddevguides");
//Setting the color of the text
text.setFill(Color.DARKSEAGREEN);
//Instanting the reflection class
Reflection reflection = new Reflection();
//setting the bottom opacity of the reflection
reflection.setBottomOpacity(0.0);
//setting the top opacity of the reflection
reflection.setTopOpacity(0.5);
//setting the top offset of the reflection
reflection.setTopOffset(0.0);
//Setting the fraction of the reflection
reflection.setFraction(0.7);
//Applying reflection effect to the text
text.setEffect(reflection);
//Creating a Group object
Group root = new Group(text);
//Creating a scene object
Scene scene = new Scene(root, 600, 300);
//Setting title to the Stage
stage.setTitle("Reflection effect example");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
次のコマンドを使用して、コマンドプロンプトから保存したJavaファイルをコンパイルして実行します。
javac ReflectionEffectExample.java
java ReflectionEffectExample
実行時に、上記のプログラムは以下に示すようにJavaFXウィンドウを生成します。