Tuesday Jan 27, 2009

Elliptical Gradient Button in JavaFX

In JavaFX, we can make our own fancy buttons. Here in this blog, I tried to write an elliptical button. Have a look.



Here is the code :


package ellipticalbutton;

import javafx.scene.effect.\*;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.\*;
import javafx.scene.Scene;
import javafx.scene.shape.\*;
import javafx.scene.text.\*;
import javafx.stage.\*;

var x=70;
var y=40;

var el:Ellipse = Ellipse {
    centerX: 120
    centerY: 100
    radiusX: bind x
    radiusY: bind y

    effect: DropShadow {
        offsetY: 3
        color: Color.color(0.3, 0.3, 0.3)
        spread:0.4
    }//end effect

    effect:GaussianBlur{
    }
    fill:RadialGradient{
        centerX:0
        centerY:0
        radius:25
        proportional:false
        cycleMethod:CycleMethod.REPEAT
        stops:[
            Stop {
                offset: 0.0
                color: Color.ANTIQUEWHITE },
            Stop {
                offset: 0.3
                color: Color.GREEN },
            Stop {
                offset: 0.8
                color: Color.ANTIQUEWHITE }
        ]

    }//end fill

    onMousePressed: function( e: MouseEvent ):Void {
        x = x - 2;
        y = y - 2;
    }

    onMouseReleased: function( e: MouseEvent ):Void {
        x = x + 2;
        y = y + 2;
    }

}//end ellipse


var t = Text {
    font: Font {
        size: 20
        name:"Verdana"
    }

    x: 90
    y: 100
    content: "Press"
    fill:Color.DARKGREEN
    effect:DropShadow{
        offsetX:10
        offsetY:10
        color:Color.DARKGRAY
    }

}//end Text

Stage {
    title: "Elliptical Button"
    //style:StageStyle.UNDECORATED
    width: 240
    height: 320
    scene: Scene {

            fill:Color.LIGHTGREY
            content: [Group{
                    content:[
                        el,
                        t
                    ]

                }
            ]
        }
}

About

I am Vikram Aroskar working in the Java team based out of India.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today