2008年12月20日土曜日

JavaFX Example

More...

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

Stage {
title: "Declaring Is Easy!"
width: 249
height: 251
visible: true
scene: Scene {
content: [
Circle {
centerX: 118
centerY: 110
radius: 83
fill: Color.WHITE
stroke: Color.RED
},
Rectangle {
x: 45 y: 35
width: 150 height: 150
arcWidth: 15 arcHeight: 15
fill: Color.GREEN
}
]
}
}



More...

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;
import javafx.scene.transform.Transform;

Stage {
title: "Nodes"
width: 220
height: 170
visible: true
scene: Scene {
fill: Color.LIGHTBLUE
content: Group {
translateX: 55
translateY: 10
content: [
Circle {
centerX: 50 centerY: 50 radius: 50
stroke: Color.YELLOW
fill: Color.WHITE
},
Text {
transforms: Transform.rotate(33, 10, 100)
content: "Duke"
},
ImageView {
image: Image {url: "http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TextSamplerDemoProject/src/components/images/dukeWaveRed.gif"}
}
]
}
}
}



More...

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.Group;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Circle;
import javafx.scene.effect.Reflection;

Stage {
title: "JavaFX Record Button"
width: 249
height: 251
visible: true
scene: Scene {
fill: LinearGradient {
startX: 0, startY: 0, endX: 0, endY: 1.0, proportional: true
stops: [
Stop {offset: 0.0 color: Color.WHITE},
Stop {offset: 1.0 color: Color.BLACK}
]
}
content: [
Group{
content: [
Rectangle {
x: 40 y: 55 width: 150 height: 50
arcWidth: 20 arcHeight: 55 stroke: Color.BLACK
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {offset: 0.0 color: Color.WHITE},
Stop {offset: 1.0 color: Color.BLACK}
]
}
},
Circle {
centerX: 115 centerY: 80 radius: 15
fill: Color.web("#ff3300") stroke: Color.DARKRED
}
]
effect: Reflection {fraction: 0.9 topOpacity: 0.5 topOffset: 2.5}
}
]
}
}



More...

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingSlider;

import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.paint.Stop;
import javafx.scene.paint.RadialGradient;

var slider = SwingSlider{
minimum: 0
maximum: 60
value: 0
translateX: 10
translateY: 110
};

Stage {
title: "Data Binding"
width: 220
height: 170
scene: Scene {
fill: Color.LIGHTGRAY;
content: [
slider,
Circle {
centerX: bind slider.value+50 centerY: 60 radius: 50
stroke: Color.YELLOW
fill: RadialGradient {
centerX: 50 centerY: 60 radius: 50
focusX: 50 focusY: 30
proportional: false
stops: [
Stop {offset: 0 color: Color.RED},
Stop {offset: 1 color: Color.WHITE},
]
}
}
]
}
visible: true
}



More...

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingToggleGroup;
import javafx.ext.swing.SwingRadioButton;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

var group = SwingToggleGroup{};

var choice1 = SwingRadioButton{
text: "STOP"
foreground: Color.GRAY
font: Font{name:"Tahoma" size: 15}
toggleGroup: group
};

var choice2 = SwingRadioButton{
text: "READY"
foreground: Color.GRAY
font: Font{name:"Tahoma" size: 15}
toggleGroup: group
};

var choice3 = SwingRadioButton{
text: "GO"
foreground: Color.GRAY
font: Font{name:"Tahoma" size: 15}
toggleGroup: group
};

var lightStop = Circle {
centerX: 12
centerY: 12
radius: 12
stroke: Color.GRAY
fill: bind RadialGradient {
centerX: 8,
centerY: 8,
radius: 12,
proportional: false
stops: [
Stop {offset: 0.0 color: Color.WHITE}
Stop {offset: 1.0 color:
if (choice1.selected)
then Color.RED
else Color.GREY
}
]
}
};

var lightReady = Circle {
centerX: 12
centerY: 12
radius: 12
stroke: Color.GRAY
fill: bind RadialGradient {
centerX: 8,
centerY: 8,
radius: 12,
proportional: false
stops: [
Stop {offset: 0.0 color: Color.WHITE}, Stop {offset: 1.0 color:
if (choice2.selected)
then Color.GOLD
else Color.GRAY
}
]
}
};

var lightGo = Circle {
centerX: 12
centerY: 12
radius: 12
stroke: Color.GRAY
fill: bind RadialGradient {
centerX: 8,
centerY: 8,
radius: 12,
proportional: false
stops: [
Stop {offset: 0.0 color: Color.WHITE},
Stop {offset: 1.0 color:
if (choice3.selected)
then Color.GREEN
else Color.GREY
}
]
}
};

Stage {
title: "Lights"
width: 220
height: 130
visible: true
scene: Scene{
fill: Color.HONEYDEW
content: HBox{
spacing: 10
content:[
VBox{
spacing: 10
content:[choice1, choice2, choice3]
},
HBox{
spacing: 15
content:[lightStop, lightReady, lightGo]
translateY: 25
}
]
}//HBox
} //Scene
}//Stage



More...

import javafx.animation.Interpolator;
import javafx.animation.Timeline;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.effect.Lighting;
import javafx.scene.effect.light.DistantLight;

var x: Number;

Timeline {
repeatCount: Timeline.INDEFINITE
autoReverse: true
keyFrames: [
at (0s) {x => 0.0},
at (7s) {x => 387.0 tween Interpolator.LINEAR},
]
}.play();

var y: Number;

Timeline {
repeatCount: Timeline.INDEFINITE
autoReverse: true
keyFrames: [
at (0s) {y => 0.0},
at (4s) {y => 55.0 tween Interpolator.LINEAR},
]
}.play();

Stage{
title: "Cloud"
visible: true
scene: Scene{
fill: Color.WHITE
content:[
ImageView{
image: Image{url: "http://java.sun.com/docs/books/tutorial/2d/basic2d/examples/images/weather-sun.png"}
},
Path {
translateX: bind x
translateY: bind y
fill: Color.WHITE
stroke: Color.LIGHTBLUE
strokeWidth: 2
effect: Lighting{light: DistantLight{azimuth: 90}}
elements: [
MoveTo { x: 15 y: 15 },
ArcTo { x: 50 y: 10 radiusX: 20 radiusY: 20 sweepFlag: true},
ArcTo { x: 70 y: 20 radiusX: 20 radiusY: 20 sweepFlag: true},
ArcTo { x: 50 y: 60 radiusX: 20 radiusY: 20 sweepFlag: true},
ArcTo { x: 20 y: 50 radiusX: 10 radiusY: 5 sweepFlag: true},
ArcTo { x: 15 y: 15 radiusX: 10 radiusY: 10 sweepFlag: true},
]
}//Path
]
}//Scene
onClose: function() {
java.lang.System.exit(0);
}//close action
}//Stage



More...

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.Group;
import javafx.scene.shape.Circle;
import javafx.scene.effect.DropShadow;
import javafx.scene.shape.Path;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.LineTo;
import javafx.scene.paint.RadialGradient;
import javafx.scene.shape.Rectangle;
import javafx.scene.effect.Lighting;
import javafx.scene.effect.Glow;
import javafx.scene.effect.light.DistantLight;
import javafx.scene.Cursor;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.MouseButton;

var effect = Glow{};
var visiblePlay: Boolean = true;
var visiblePause: Boolean = false;
var play: Boolean = false;

Stage {
title: "FXButton"
width: 170 height: 170
visible: true
scene: Scene {
fill: LinearGradient {
startX: 0, startY: 0, endX: 1, endY: 1, proportional: true
stops: [
Stop {offset: 0.0 color: Color.WHITE},
Stop {offset: 1.0 color: Color.GRAY}
]
}
content: [
Group{
cursor: Cursor.HAND
effect: effect
content: [
Circle {
centerX: 70
centerY: 70
radius: 40
fill:LinearGradient {
startX: 0
startY: 0
endX: 1
endY: 1
stops: [
Stop { offset:0 color: Color.web("#0099CC") },
Stop { offset:1 color: Color.web("#000099") }
]
}
effect: DropShadow{
offsetX: 5
offsetY: 5
color: Color.BLACK
}
},
Circle {
centerX: 70
centerY: 70
radius: 34
fill: bind RadialGradient {
centerX:0.5
centerY:0.5
radius:0.5
stops: [
Stop { offset:0 color: Color.web("#0099CC",0) },
Stop { offset:1 color: Color.web("#0099CC",1.0) }
]
}
effect: DropShadow{
offsetX: 2
offsetY: 2
color: Color.BLACK
}
},
Path{
visible: bind visiblePlay;
fill: Color.BLACK
elements: [
MoveTo { x: 63 y: 53 }, LineTo { x: 63 y: 84},
LineTo { x: 83 y: 68 }, LineTo {x: 63 y:53}
]
effect: Lighting{ light: DistantLight{azimuth: 90}}
},
Rectangle {
visible: bind visiblePause;
x: 57 y: 53 width: 9 height: 30
stroke: Color.BLACK fill: Color.BLACK
effect: Lighting{ light: DistantLight{azimuth: 90}}
},
Rectangle {
visible: bind visiblePause;
x: 73 y: 53 width: 9 height: 30
stroke: Color.BLACK fill: Color.BLACK
effect: Lighting{ light: DistantLight{azimuth: 90}}
},
]

onMouseEntered: function(evt: MouseEvent):Void {
effect.level = 0.65;
}

onMouseClicked: function(evt: MouseEvent):Void {
if(evt.button == MouseButton.PRIMARY) {
if(play == true){
visiblePlay = true;
visiblePause = false;
play = false
}
else{
visiblePlay = false;
visiblePause = true;
play = true;
}
}
}

onMousePressed: function(evt: MouseEvent):Void {
if(evt.button == MouseButton.PRIMARY) {
effect.level = 0.0;
}
}

onMouseReleased: function(evt: MouseEvent):Void {
effect.level = 0.65;
}

onMouseExited: function(evt: MouseEvent):Void {
effect.level = 0.3;
}
},
]
}
}

1 件のコメント: