Skip to main content

handling with arrays

5 replies [Last post]
uro
Offline
Joined: 2008-05-18

Hello,

I´m only a stupid php-developer, who wants to create a little desktop application with JavaFX for the first time...

My problem:
I want to create a Menu with Label values coming from a database.
------------------
class Tutorial extends CompositeNode {
...
private attribute labelList: String*;
...
}

attribute Tutorial.labelList["fo1","fo2"];

When I put the values hardcoded in the attribute-statement, my "foreach loop" in the Menu construct works :)
-----------

attribute Tutorial.menu = Menu {
items : foreach(i in [0..sizeof labelList-1])
[
MenuItem{
name:"{labelList[i]} "
----------

But this way fails:

attribute Tutorial.labelList[];

insert "Ludger" into Tutorial.labelList;
insert "Hugo" into Tutorial.labelList;
insert "Theobald" into Tutorial.labelList;

What goes wrong?

I use NeatBean 6.0.1 and JavaFX 1.0.5, the *interpreted* version

Thanks in advance!

uro

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

The *interpreted* version of JavaFX Script language is not longer supported.
Please, use a compiler one: http://javafx.netbeans.org/download-compiler-JFXplugin.html

uro
Offline
Joined: 2008-05-18

Hello alexsch,

thank you for the answer.

Unfortunately my examples to learn and try out JavaFX Scripts are in the "old-style" mode :(
The JavaFX books from James L. Weaver and Ralf Steyer (in german) deal with this old-style syntax... So,what can I do?

alexsch
Offline
Joined: 2007-07-12

Could you post the whole example?
It helps to understand the problem.

uro
Offline
Joined: 2008-05-18

The source based of the file Tutorial.fx from the "JavaFX 2D Graphics Tutorial" (Netbeans 6.0.1)

My target is to create a menu on the left side and two right frames: in the top frame is a form and in the bottom frame a picture. If I click on one of this menu buttons, the content in the frames are changing in relationship with the menu item.

With hardcodes values (attribute Tutorial.labelList=["Patient01"..) this application runs.

But I want to get the values for the variables from a database. How can I fill/serializise the variables? I have tried to make an instance and so one, but the values of this instance aren´t visible in the area of "attribute Tutorial.menu = Menu".

You see, for me is difficult to understand the concepts of Java/JavaFX....

Thank you for supporting me!

Tutorial.fx:

------------------------------------------------
class Tutorial extends CompositeNode {
private attribute current: String;
private attribute source: String;
private attribute valueScore: Number;
private attribute labelList: String*;
private attribute PIPleftList : Number*;
private attribute PIPleftPictureList : String*;
private attribute MCPleftList : Number*;
private attribute MCPleftPictureList : String*;

public attribute menu:Menu;
attribute height:Number;
attribute width:Number;
private attribute splitIndex:Number;

}
attribute Tutorial.height = 438;
attribute Tutorial.width = 872;
attribute Tutorial.splitIndex = 0.5;
attribute Tutorial.source = "testbild1.jpg";
attribute Tutorial.labelList = ["Patient01","Patient02","Patient03"];

attribute Tutorial.PIPleftList = [0,4,3];
attribute Tutorial.MCPleftList = [2,1,4];
attribute Tutorial.PIPleftPictureList = ["testbild1.jpg","testbild2.jpg","testbild1.jpg"];
attribute Tutorial.MCPleftPictureList = ["testbild2.jpg","testbild1.jpg","testbild2.jpg"];

attribute Tutorial.menu = Menu {
items : foreach(a in [0..sizeof labelList-1])
[
MenuItem{
name:"{labelList[a]}"
hasSubMenu:true
subMenu:[
MenuItem{
name:"PIP left"
action:operation(){current="{PIPleftList[a]}";source="{PIPleftPictureList[a]}";valueScore=PIPleftList[a];}
},
MenuItem{
name:"MCP left"
action:operation(){current="{MCPleftList[a]}";source="MCPleftPictureList[a];";valueScore=MCPleftList[a];}
}
]
},
]
};

operation Tutorial.composeNode() {
...
...
}

---------------------------------------------------------

alexsch
Offline
Joined: 2007-07-12

I guess you need to use [b]bind[/b] operator before [b]foreach[/b] statement

items : [b]bind [/b]foreach(label in labelList])

----------------------------------------------------------------------------------
[code]
attribute Tutorial.menu = Menu {
items : bind foreach(label in labelList])
[
MenuItem{
name:"{label}"
hasSubMenu:true
subMenu:[
MenuItem{
name:"PIP left"
action:operation(){current="{PIPleftList[indexof label]}";source="{PIPleftPictureList[indexof label]}";valueScore=PIPleftList[indexof label];}
},
MenuItem{
name:"MCP left"
action:operation(){current="{MCPleftList[indexof label]}";source="MCPleftPictureList[indexof label];";valueScore=MCPleftList[indexof label];}
}
]
},
]
};
[/code]