Skip to main content

Help me! (something about logic & syntax in JavaFX)

2 replies [Last post]
joecolejoe
Offline
Joined: 2008-06-18
Points: 0

FIRST PROBLEM !!!

This code has no errors when BUILD in NetBeans 6.1 (with JavaFX plugin).
But when RUN, everything is ok until I click "Keys -> Disabled" menu.
There are lots of exceptions and I can't use button ( labeled "1" )
although "Disabled" is unchecked.

/*=============== CODE ============*/

import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.ui.filter.*;
import java.lang.System;
class KeyPadModel {
attribute keysDisabled: Boolean;
attribute letterClicked: String;
}
var kpModel = KeyPadModel {
keysDisabled: true
letterClicked: '0'
};
Frame {
title: "The Key Pad Exercise"
height: 400
width: 400
visible: true
// menubar
menubar: MenuBar {
menus: Menu {
text: "Keys"
items: [
CheckBoxMenuItem {
selected: bind kpModel.keysDisabled
text: "Disabled"
accelerator: Accelerator{
modifier: KeyModifier.CTRL
keyStroke: KeyStroke.D
}
},
MenuItem {
text: "Exit"
action: function() {
System.exit(0);
}
}
]
}
} // end menubar

// content
content: BorderPanel {
// top of BorderPanel
border: EmptyBorder {
top: 30
left: 30
right: 30
bottom: 30
}
top: SimpleLabel {
horizontalAlignment: HorizontalAlignment.TRAILING
border: EmptyBorder {
bottom: 20
}
text: bind kpModel.letterClicked
}
center: GridPanel {
rows: 1
columns: 1
cells:
Button {
text: "1"
enabled: bind not kpModel.keysDisabled
action: function() {
kpModel.letterClicked = '1';
}
}
}
} // end content
}

/*=============== END ============*/

SECOND PROBLEM !!!

When I copy this code to JavaFX Pad's editor.
It's required to modify:
1. "funtion" -> "operation"
2. "HorizontalAlignment.TRAILING" -> "TRAILING"
3. "KeyModifier.CTRL" -> "CTRL"
4. "KeyStroke.D" -> "D"

Then, I can use the button "1".

1. Why It need to modify 4 items above?
2. Why I can't use the button at first problem ( in NetBeans ).
Then, there isn't important code which is changed ( I think so ), I can use this button in JavaFX Pad.

Please show me all mystery!
Thank for any help!

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

> FIRST PROBLEM !!!
>
> This code has no errors when BUILD in NetBeans 6.1
> (with JavaFX plugin).
> But when RUN, everything is ok until I click "Keys ->
> Disabled" menu.
> There are lots of exceptions and I can't use button (
> labeled "1" )
> although "Disabled" is unchecked.

Use [b]bind with inverse[/b] operator for the bijective binding, that solves your problem:

[code]
CheckBoxMenuItem {
selected: bind kpModel.keysDisabled with inverse
}
[/code]

> SECOND PROBLEM !!!
>
> When I copy this code to JavaFX Pad's editor.
> It's required to modify:
> 1. "funtion" -> "operation"
> 2. "HorizontalAlignment.TRAILING" -> "TRAILING"
> 3. "KeyModifier.CTRL" -> "CTRL"
> 4. "KeyStroke.D" -> "D"
>
> Then, I can use the button "1".
>
> 1. Why It need to modify 4 items above?
> 2. Why I can't use the button at first problem ( in
> NetBeans ).
> Then, there isn't important code which is changed ( I
> think so ), I can use this button in JavaFX Pad.

The JavaFX Pad uses Interpreter version of JavaFX Script language that uses slightly
different syntax and is not supported now.

>
> Please show me all mystery!
> Thank for any help!

joecolejoe
Offline
Joined: 2008-06-18
Points: 0

MenuItem {
text: "Open Project..."
mnemonic: /** what code should I type here to make "e" in "Project" is underlined instead of "e" in "Open" -- if I type: "KeyStroke.E", the result is underlined "e" in "Open" */
}