JavaFX | DropShadow类

DropShadow类是JavaFX的一部分。DropShadow类创建高级效果,以指定的半径、扩散、模糊类型和偏移来渲染内容后面的对象阴影。DropShadow类继承 效应

null

类的构造函数:

  1. DropShadow() :创建DropShadow的新对象。
  2. DropShadow(模糊类型、颜色、双半径、双扩散、双偏移、双偏移) :使用指定值blurType、radius、spread、offsetX、offsetY创建DropShadow的新对象。
  3. DropShadow(双半径,彩色) :使用指定的半径和颜色值创建DropShadow的新对象。
  4. DropShadow(双半径、双偏移、双偏移、彩色) :使用指定的半径、偏移量、偏移量和颜色值创建DropShadow的新对象。

常用方法:

方法 解释
getBlurType() 返回效果的模糊类型。
getColor() 返回效果的颜色。
getInput() 返回属性输入的值。
getRadius() 返回dropShadow效果的半径。
B型(v型) 设置dropShadow效果的模糊类型。
设置颜色(颜色v) 设置dropShadow效果的颜色。
设置输入(效果v) 设置属性输入的值。
设置半径(双v) 设置dropshadow效果的半径。
setOffsetX(双v) 设置offsetX的值。
setOffsetY(双v) 设置offsetY的值。
getOffsetX() 返回offsetX的值。
getOffsetY() 返回offsetY的值。
getSpread() 返回阴影效果的扩散值。
固定支架(双v) 设置阴影效果的扩散值。

下面的程序演示了DropShadow类的使用:

  1. Java程序创建一个圆并向其添加DropShadow效果: 在这个程序中,我们将创建一个名为 圆圈 并创建一个DropShadow效果 投下阴影 具有指定的半径和颜色。DropShadow效果将使用 setEffect() 函数和圆圈将被添加到组中。这些圆圈将被转换到舞台上的特定位置 setTranslateX() setTranslateY() 作用团队将被添加到场景中,场景将被添加到舞台中。

    // Java program to create a Circle and
    // add DropShadow effect to it
    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.scene.shape.Circle;
    import javafx.scene.paint.Color;
    import javafx.scene.Group;
    public class drop_shadow_1 extends Application {
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "drop_shadow example" );
    // create a circle
    Circle circle = new Circle( 50 .0f, 50 .0f, 25 .0f);
    // set fill for circle
    circle.setFill(Color.BLUE);
    // translate to a position
    circle.setTranslateX( 50 .0f);
    circle.setTranslateY( 50 .0f);
    // create a drop_shadow effect
    DropShadow drop_shadow = new DropShadow( 10 , Color.RED);
    // set effect
    circle.setEffect(drop_shadow);
    // create a Group
    Group group = new Group(circle);
    // create a scene
    Scene scene = new Scene(group, 200 , 200 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输出:

    图片[1]-JavaFX | DropShadow类-yiteyi-C++库

  2. Java程序创建四个圆并向其添加DropShadow效果,它们具有不同的模糊类型和不同的offsetX、offsetY和radius值: 在这个程序中,我们将创建名为 圆圈 , 圆圈1 , 圆圈2 , 圆圈3 并创建一个名为 投下阴影1 , 投下阴影2 , 投下阴影3 , 投下阴影4 具有指定的半径、颜色、偏移量、偏移量、扩散和模糊类型。DropShadow效果将使用 setEffect() 函数和圆圈将被添加到组中。这些圆圈将被转换到舞台上的特定位置 setTranslateX() setTranslateY() 作用团队将被添加到场景中,场景将被添加到舞台中。

    // Java program to create four Circles and
    // add DropShadow effect to it which are of
    // different blur types and different values
    // of offsetX, offsetY and radius
    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.scene.shape.Circle;
    import javafx.scene.paint.Color;
    import javafx.scene.Group;
    public class drop_shadow_2 extends Application {
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "drop_shadow example" );
    // create a circle
    Circle circle = new Circle( 0 .0f, 0 .0f, 25 .0f, Color.RED);
    Circle circle1 = new Circle( 0 .0f, 0 .0f, 25 .0f, Color.RED);
    Circle circle2 = new Circle( 0 .0f, 0 .0f, 25 .0f, Color.RED);
    Circle circle3 = new Circle( 0 .0f, 0 .0f, 25 .0f, Color.RED);
    // translate to a position
    circle.setTranslateX( 50 .0f);
    circle.setTranslateY( 50 .0f);
    // translate to a position
    circle1.setTranslateX( 150 .0f);
    circle1.setTranslateY( 50 .0f);
    // translate to a position
    circle2.setTranslateX( 50 .0f);
    circle2.setTranslateY( 150 .0f);
    // translate to a position
    circle3.setTranslateX( 150 .0f);
    circle3.setTranslateY( 150 .0f);
    // create drop_shadow effect
    DropShadow drop_shadow1 = new DropShadow(BlurType.values()[ 0 ],
    Color.BLUE, 5 , 3 .0f, 2 .0f, 2 .0f);
    DropShadow drop_shadow2 = new DropShadow(BlurType.values()[ 1 ],
    Color.BLUE, 5 , 3 .0f, 3 .0f, 3 .0f);
    DropShadow drop_shadow3 = new DropShadow(BlurType.values()[ 2 ],
    Color.BLUE, 5 , 4 .0f, 3 .0f, 3 .0f);
    DropShadow drop_shadow4 = new DropShadow(BlurType.values()[ 3 ],
    Color.BLUE, 5 , 4 .0f, 2 .0f, 2 .0f);
    // set effect
    circle.setEffect(drop_shadow1);
    circle1.setEffect(drop_shadow2);
    circle2.setEffect(drop_shadow3);
    circle3.setEffect(drop_shadow4);
    // create a Group
    Group group = new Group(circle, circle1, circle2, circle3);
    // create a scene
    Scene scene = new Scene(group, 400 , 400 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输出:

    图片[2]-JavaFX | DropShadow类-yiteyi-C++库

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

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

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