Skip to main content

. . . be amicable to posting a simple .fx example . . .

5 replies [Last post]
peterdasilva
Offline
Joined: 2007-01-30
Points: 0

Would the fine JavaFX engineers at Sun be amicable to posting a simple .fx example demonstrating a few of its capabilities? It would be great if the example could demonstrate; reading and manipulating data from an external xml file, mouse over graphics' action, single / double click graphics' action, pop up a drop down list on mouse over and execute an action unique to the selected list item in drop down, write an external file which lists for example the mouse actions.

At this stage in the JavaFX life cycle, a substantive code demo would be very much appreciated!

Thanks,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

And you can also load fx files:
[code]
----------------------------------------------------- Planets.fx ------------------------------------------------

PlanetarySystem{
planets: [
Planet{
name: "Sun"
mass : 2e30
color: Color.YELLOW
radius: 14000
coordinate : [ 0 , 0 ]
velocity : [ 0, 0 ]
},Planet{
name: "Mercury"
mass : 3.3e23
color: Color.BLUE
radius: 2400
coordinate : [ -57e9 , 0]
velocity : [ 0, -47e3 ]
},
Planet{
name: "Venus"
mass : 4.8e24
color: Color.PINK
radius: 6000
coordinate : [ 108e9 , 0]
velocity : [ 0, 35e3 ]
},
Planet{
name: "Earth"
mass : 6e24
color: Color.GREEN
radius: 6300
coordinate : [ 0 , -150e9 ]
velocity : [ 30e3, 0 ]
},Planet{
name: "Mars"
mass : 6.4e23
color: Color.RED
radius: 3400
coordinate : [ 0 , 228e9 ]
velocity : [ -24e3, 0 ]
}
]
};

----------------------------------------------------- Util.java ------------------------------------------------

public static Object runFXFile(String name) throws Exception {
return runFXFile(name, Thread.currentThread().getContextClassLoader());
}

public static Object runFXFile(String name, ClassLoader classLoader) throws Exception {
try {
Class cls = classLoader.loadClass(name);
Method run = cls.getDeclaredMethod(Entry.entryMethodName(), Sequence.class);
Object args = Sequences.make(String.class, commandLineArgs);
return run.invoke(null, args);
} catch (Throwable e) {
throw new Exception("FX file: \"" + name + "\" was not compiled!!", e);
}
}

----------------------------------------------------- Main.fx ------------------------------------------------

var planetarySystem = Util.runFXFile("Planets") as PlanetarySystem;

-------------------------------------------------------------------------------------------------------------------
[/code]

peterdasilva
Offline
Joined: 2007-01-30
Points: 0

Alex, thank you for your post! A question I still have is, by using your binding example, how would I read an external xml file to pull from it the title "Animals" and also populate the string array animals with dog and cat.
Thanks,
Peter

alexsch
Offline
Joined: 2007-07-12
Points: 0
surikov
Offline
Joined: 2007-05-26
Points: 0

look to this page

http://molgav.nn.ru/surikov/files/jfx/JFXNote.html

1.Fullscreen transparent painter
2.BreakOut style game with sound

source code included
webstart not tested yet so local version only

alexsch
Offline
Joined: 2007-07-12
Points: 0

[code]
------------------------ Button Example --------------------------------
import javafx.ui.*;
import java.lang.System;

Frame {
title: "JavaFX Button"
width: 200
height: 100
content: Button {
text: "Click Me"
action: function(){
System.out.println("Button is pressed");
}
}
visible: true
}
----------------------------------- Drop Down List ----------------------------

import javafx.ui.*;

var animals = [ "dog", "cat", "mouse" ];
var index = -1;

ComboBox{
cells: bind for (animal in animals){
ComboBoxCell{
text: animal
}
}
selection: bind index with inverse
}

----------------------------------- Mouse Events ----------------------------

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;

Frame {
title: "Mouse Events"
width: 200
height: 100
content: Canvas {
var x = 100.0
var y = 30.0
content: Circle {
cx : bind x
cy : bind y
radius: 25
fill: Color.ORANGE
stroke: Color.GREEN

onMousePressed: function(e:CanvasMouseEvent){
System.out.println("Mouse pressed x={e.x} y={e.y}");
}

onMouseReleased: function(e:CanvasMouseEvent){
System.out.println("Mouse released x={e.x} y={e.y}");
}

onMouseDragged: function(e:CanvasMouseEvent) {
var xy = e.localDragTranslation;
x += xy.x;
y += xy.y;
}

}
}
visible: true
}

---------------------- Animation ---------------------------------------

import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.animation.*;

var radius = 0.0;

var timeline = Timeline {
keyFrames: KeyFrame {
time: 5s,
values: radius => 100 tween Interpolator.LINEAR
action: function() { /* User action */}
}
repeatCount: 3
}

timeline.start();

Frame{
width: 200
height: 200
title: "JavaFX Animation"
content: Canvas{
content: Circle{
transform: Transform.translate(100, 100);
radius: bind radius
fill: Color.ORANGE
}
}
visible: true
}

---------------------- Binding ---------------------------------------

import javafx.ui.*;

var animals:String[] = [ "dog", "cat" ];
var animal:String;

Frame{
title: "Animals"
content: BorderPanel{
top: TextField{ text: bind animal with inverse}
center: ListBox {
cells: bind for(str in animals){
ListCell{ text: str}
}
}
bottom: Button{
text: "Add Animal"
action: function(){ insert animal into animals; }
}
}
visible: true
}

---------------------------------------------------------------------------------------
[/code]