Referers



JavaFX: Using both a Frame and an Application

07.29.2008 | 0 Comments

I'm building out our first JavaFX offering and ran into this so I'd thought I'd share my solution.  I'm building an applet, and in Netbeans you have to right click on the .fx file that defines the applet to run it.  Running the project does not launch the applet.  While this is arguably a shortcoming in the Netbeans JavaFX plugin, it got me to thinking, what if you wanted to have both a frame and an applet.

 To do this first create a Main.fx file which defines your frame.  Main.fx is the default main class created when you create a new Netbeans JavaFX project.   Your Main.fx Frame definition should look like this:


Frame {

visible: true
width: 480
height: 360

var _stage: Stage

stage:
_stage = Stage {
content: [
AppGroup {
stage: bind _stage;
}
]
fill: Color.web("#eebd3a", 1.0)
}
}

 

Notice that I have defined a custom node called AppGroup.  I'll get to that in a bit...

 Next I created a Applet.fx file which contains the Application definition:


Application {

var _stage: Stage

stage:
_stage = Stage {
content: [
AppGroup {
stage: bind _stage;
}
]
fill: Color.web("#eebd3a", 1.0)
}
}

 Notice that the the same AppGroup custom node is included as the content of the stage in the Application.  All that's left is to create the custom node called AppGroup as follows:


public class AppGroup extends CustomNode {

public attribute stage: Stage;

public function create(): Node {
return Group {
content: [
.
.
.
]
}
}
}

 Now you can run the project which launches Main.fx and creates a Frame.  Or you can select Applet.fx and choose run applet to run the applet.

 


« Greetings | Main | JavaFX: Texture... »

Comments:

Post a Comment:
Comments are closed for this entry.