JAXAFX:实现倒影特效

本文介绍如何使用 JavaFX 实现窗口背景渐变效果及按钮的反射效果,包括设置线性渐变、添加反射效果等具体实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.image.Image;
import javafx.scene.Node;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform;
import javafx.scene.shape.Rectangle;
import javafx.scene.effect.Reflection;
import javafx.scene.Group;
/**
 * @author Smartken
 */

Stage{
    height:600
    width:800
    visible:true
    scene:Scene{
        fill:LinearGradient{
            startX:0
            startY:0
            endX:800
            endY:600
            proportional:false
            stops:[Stop{
                    offset:0.0
                    color:Color.WHITESMOKE},
                Stop{
                    offset:1.0
                    color:Color.BLACK}]
        }
        content:[Group{         //Group自身是一个Node,但它也可以包含多个Node
                content: [Rectangle {
                x: 400,
                y: 300
                width: 120,
                height: 60
                arcHeight:60
                arcWidth:20
                stroke: Color.BLACK
                fill:null
            },Circle {
                centerX: 460,
                centerY: 330
                radius: 20
                fill: Color.RED
            }  ]
            effect:Reflection{fraction:0.8 topOffset:3 topOpacity:0.7 }  

 

  //reflection 对象字面值具有一个 fraction 实例变量,该变量用来定义在映像中可见的按钮区域的百分比。topOpacity 变量用来定义映像的不透明性度,topOffset 用来定义按钮底部与映像顶部之间的距离。
 
}

          ]
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值