Skip to main content

Help me! (about move code to separate file)

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

I used JavaFX Pad.
This code works fine if I put it in a single file.

package jfx_book;
import javafx.ui.*;
import javafx.ui.canvas.*;

/* this class will be moved to file named: hatTwoMessageModel.fx */
class hatTwoMessageModel {
attribute messOne:String;
attribute messTwo:String;
}

Frame {
var tmpModel = hatTwoMessageModel {
messOne: "Mannschaft"
messTwo: "Portugal"
}

title: "The Two Message Exercise"
height: 120
width: 400
content:
Canvas {
content:[
Text {
font:
Font {
faceName: "Times New Roman"
size: 40
}
stroke: red
x: 10
y: 10
content: bind tmpModel.messOne
},
Text {
font:
Font {
faceName: "Amazone"
size: 70
}
stroke: blue
fill: white
x: 150
y: 50
content: bind tmpModel.messTwo
}
]
}
visible: true
}

But when I cut and pasted the class hatTwoMessageModel to file with the same name ( with .fx extension and I also included "package jfx_book;" at beginning of the file), there were errors:

No such attribute messOne in incomplete class jfx_book.hatTwoMessageModel
No such attribute messTwo in incomplete class jfx_book.hatTwoMessageModel

By the way, how could I keep format of code when it was posted.
When I typed this Post Message, I typed the code clearly, but when I clicked "Post Message", there weren't any taps, spaces that I've typed as a result.
Please help me!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shagus
Offline
Joined: 2007-05-10

Hi, here is the working example:

//--------- hatTwoMessageModel.fx -----------------------

package jfx_book;

class hatTwoMessageModel {
attribute messOne:String;
attribute messTwo:String;

}

//-----------------------------Test.fx -------------------------

package jfx_book;
import javafx.ui.*;
import javafx.ui.canvas.*;

Frame {
var tmpModel = hatTwoMessageModel {
messOne: "Mannschaft"
messTwo: "Portugal"
}

title: "The Two Message Exercise"
height: 120
width: 400
content:
Canvas {
content:[
Text {
font:
Font {
faceName: "Times New Roman"
size: 40
}
stroke: Color.RED
x: 10
y: 10
content: bind tmpModel.messOne
},
Text {
font:
Font {
faceName: "Amazone"
size: 70
}
stroke: Color.BLUE
fill: Color.WHITE
x: 150
y: 50
content: bind tmpModel.messTwo
}
]
}
visible: true
}

//----------------------------------------------

//------compile

javafxc -d . *.fx

//Run

javafx jfx_book.Test

joecolejoe
Offline
Joined: 2008-06-18

Thank U.

But I want it works fine in JavaFX Pad, not in command line.
What should I do? :-)