Steve On Java

Hacking Java, JavaFX, and Flash with Agility

Stephen Chin

2008

  • JFXtras 0.1 Release - Grids, Dialogs, Testing, and more!

    The JavaFX 1.0 release came out a couple weeks ago, but one of the big questions has been about missing UI functionality, such as layouts, menus, and UI components. Future release of JavaFX will support this, but in the meantime application developers are stuck up the river without a paddle.

  • Migrating from the JavaFX Preview Release

    Now that the JavaFX 1.0 Release is out, it is time to dust off all your old JavaFX code and fire it up, right? Well, not quite... There were a whole lot of changes in the span of a few months, and it is guaranteed that your program will need a little TLC before it runs. Fortunately, I've already gone through this pain on a relatively large codebase (WidgetFX), and can share what I learned. Language Changes Change "attribute" to "var"/"def" - There is no more attribute keyword, but it is a simple search and replace to change it to var everywhere. On a second pass you might want to convert vars that are never changed to def for efficiency. No More "static" - If you want to make a variable or function as static, just move it outside your class declaration. If it is declared public you can access it from anywhere else just by prefacing it with the file name, no static modifier needed. New Access Modifiers - The default access modifier was changed to private rather than package, so you need to change any attributes or functions that had no modifier to package and then can delete all references to private. On a second pass it may be a good idea to button-up permissions by using the new public-init and public-read permissions. Here is a quick-reference table: Preview 1.0 Migration private default Remove this keyword everywhere default package Add package anywhere no modifier was specified protected protected No change public public No change N/A public-init Use this anywhere the user should be able to initialize and read, but not update N/A public-read Use this anywhere the user should be able to read, but not initialize or update Required "override" - It is now mandatory that you use the override keyword on any member variable or function that exists in the superclass. Expect to be going through lots of compiler errors to find all the places you need to fix this... {} Instead of "+" for Concatenating Strings - While the java-esque "+" operator for concatenating strings was an easy habit to fall into, it is no longer valid. Instead you have to use the {} syntax to build strings. For example, rather than "hungry for: " + meat, you would write "hungry for: {meat}". Keyframe Syntax - While this is not required to get your code working, there is a new KeyFrame syntax for doing animation that has the potential to make your code much shorter. Rather than creating an instance of the KeyFrame class you can simply write "at (duration) {x => y}". On Applications, Stages, Scenes, and Nodes All your previous conceptions of what the terms application, stage, and scene meant have now been blown away. For those of us who got very wired in to the old terminology, here is a quick reference from the old to the new: Preview 1.0 Explanation Application Stage A Stage is now the top level container, which creates a Frame when run stand-alone or becomes the content area in an Applet. Stage Scene The Scene is a grouping of Node content that can be added to a Stage. It has some useful properties including the stylesheet. Node Node Nodes remain largely unchanged, and are the base class of everything else that is visible in JavaFX. Note that you can return a Stage, Scene, or Node from your main class and they will all work within an execution context (such as an Applet).

  • WidgetFX @ the JavaFX 1.0 Launch

    Thursday evening was the big JavaFX 1.0 Launch, and the WidgetFX crew was not going to be left out, so we crashed the party in style.