In a previous post, I gave you an introduction to the 2D graphics capabilities of JavaFX Script. I also directed you to the JavaFX Canvas Tutorial, which is an excellent resource for understanding and experimenting with JavaFX Script 2D graphics and the Canvas widget. In this post, I'd like you to play with a simple example program on PlanetJFX called Scribble, and then examine its short code listing. You can do this easily by pasting the code from the PlanetJFX page referenced above into JavaFXPad (see previous posts for installing/invoking JavaFXPad). Here's my salute to The Hitchhiker's Guide to the Galaxy using Scribble:
As you look at the source code, it will be helpful to have the JavaFX Canvas tutorial available. This is because you'll find, for example, the Polyline
class in the Shapes section, the Group
class in the Groups section, the CompositeNode
class in the User Defined Graphics Objects section, and the CanvasMouseEvents
class in the Input Events section. By the way, this line of code from the example requires some additional explanation:
var: self
This creates a reference named self
to the object being literally defined (in this case a Group
object). You'll noticed that it is used later in the program to reference the content
attribute of the Group
instance:
insert polyline as last into self.content;
By the way, ScribbleRect.fx
was originated by Sven Drieling, and developed with some help from others in the PlanetJFX community.
Regards,
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Comments