Archive for the 'JavaFX Blogs' Category


Reversi 0

I developed my first implementation of the Reversi game on BASIC 20 years ago. Since then, I ported it on each programming language I studied: Turbo Pascal with graphics library and Turbo Vision, C with the Windows API, C++ with the ClanLib, Java AWT applet, and Swing application with Java2D. Now I am ready to publish yet another implementation, on JavaFX Script.


Reversy 8×8

Reversy 10×10

This game allows to compete with one of the algorithms as well as to see how these algorithms compete with each other. The Sergey algorithm is based on the Minimax algorithm with a simple table of game piece weights where the calculation depth is 6. The Pavel algorithm is developed by my colleague, and I have got it from the official JavaFX site.

I run the algorithm competition during the past weekend. Below are the results:

  • Pavel versus Sergey: 5653 wins, 363 draws, 8605 losses;
  • Sergey versus Pavel: 8563 wins, 299 draws, 6612 losses.

In addition, I discovered that my algorithm is often wins, turning all the opponent’s pieces. The reason is that Pavel uses an algorithm to minimize available moves of the opponent. He promised to complete the evaluation function soon.

Would you like to join the battle of algorithms?

Filed under: game, graphics
Go to Source

JavaFX Animation (No image included) 0

The Beauty of JavaFX(100% JavaFX).



Filed under: Uncategorized
Go to Source

What posts would you like to see about HTML5? 0

Now that HTML5 is coming of age, I've been exploring synergies between JavaFX and HTML5 in order to leverage the strengths of both.  Are there areas of HTML5, like WebSockets for example, that you'd like to see posted on this blog?

Regards,

Jim Weaver

Go to Source

What posts would you like to see about HTML5? 0

Now that HTML5 is coming of age, I’ve been exploring synergies between JavaFX and HTML5 in order to leverage the strengths of both.  Are there areas of HTML5, like WebSockets for example, that you’d like to see posted on this blog?

Regards,

Jim Weaver


Go to Source

A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it'd be useful to post a simple example.  This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers.  Here's a screen shot:

Screen shot 2010-05-31 at 9.53.25 AM
There are actually two ways to create custom layouts in JavaFX: 

  1. Sub-class javafx.scene.layout.Container
  2. Create a javafx.scene.layout.Panel instance

Here is the code from today's example that employs the first way.  Note that I'm leveraging the Node#id instance variable to supply the directional values needed by the traditional BorderLayout.

/*
 * BorderLayout.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample.layout;

import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

public class BorderLayout extends Container {
  var topHeight:Number;
  var bottomHeight:Number;
  var leftWidth:Number;
  var rightWidth:Number;

  override function doLayout():Void {
    for (node in getManaged(content)) {
      if (node.id == "top") {
        topHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, 0);
      }
      else if (node.id == "bottom") {
        bottomHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, height - bottomHeight);
      }
      else if (node.id == "left") {
        leftWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, 0, topHeight);
      }
      else if (node.id == "right") {
        rightWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, width - rightWidth, topHeight);
      }
      else if (node.id == "center") {
        setNodeWidth(node, width - (leftWidth + rightWidth));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, leftWidth, topHeight);
      }
    }
  }
  override function getPrefWidth(height:Number):Number {
    return width;
  }
  override function getPrefHeight(width:Number):Number {
    return height;
  }
}

Here is a code example of using the BorderLayout shown above.

/*
 * ContainerSubclassLayoutExample.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import containersubclasslayoutexample.layout.BorderLayout;

var nodes = [
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
  Button {
    text: "Center"
    id: "center"
  }
];

Stage {
  var sceneRef:Scene;
  title: "Container Subclass Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      BorderLayout {
        width: bind sceneRef.width
        height: bind sceneRef.height
        content: nodes
      }
    ]
  }
}

Lastly, here is an example of defining the BorderLayout custom layout functionality using the second way listed above, which is to create a Panel instance and override its behavior:

/*
 * PanelLayoutExample.fx -
 * Example of using a Panel to create a custom layout
 */

package panellayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

var nodes = [
  Button {
    text: "Center"
    id: "center"
  },
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
];

Stage {
  var panel:Panel;
  var sceneRef:Scene;
  title: "Panel Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      panel = Panel {
        var topHeight:Number;
        var bottomHeight:Number;
        var leftWidth:Number;
        var rightWidth:Number;
        content: bind nodes
        width: bind sceneRef.width
        height: bind sceneRef.height
        onLayout: function():Void {
          for (node in getManaged(panel.content)) {
            if (node.id == "top") {
              topHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, 0);
            }
            else if (node.id == "bottom") {
              bottomHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, panel.height - bottomHeight);
            }
            else if (node.id == "left") {
              leftWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, 0, topHeight);
            }
            else if (node.id == "right") {
              rightWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, panel.width - rightWidth, topHeight);
            }
            else if (node.id == "center") {
              setNodeWidth(node, panel.width - (leftWidth + rightWidth));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, leftWidth, topHeight);
            }
          }
        }
        prefWidth: function(height:Number):Number {
          return panel.width;
        }
        prefHeight: function(width:Number):Number {
          return panel.height;
        }
      }
    ]
  }
}

To learn more about using and creating layouts in JavaFX 1.3, see the blog posts that Amy Fowler has been writing on the subject, and the Custom Layouts chapter in the upcoming new edition of the Clarke/Bruno/Connors JavaFX book.

A note regarding the JavaFX RIA Exemplar Challenge: We have received several entries and I'm in the process of packaging them up and sharing them with the judges.  The winner will be announced in early June, 2010.

Regards,

Jim Weaver

Go to Source

A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it’d be useful to post a simple example.  This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers.  Here’s a screen shot:

Screen shot 2010-05-31 at 9.53.25 AM
There are actually two ways to create custom layouts in JavaFX: 

  1. Sub-class javafx.scene.layout.Container
  2. Create a javafx.scene.layout.Panel instance

Here is the code from today’s example that employs the first way.  Note that I’m leveraging the Node#id instance variable to supply the directional values needed by the traditional BorderLayout.

/*
 * BorderLayout.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample.layout;

import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

public class BorderLayout extends Container {
  var topHeight:Number;
  var bottomHeight:Number;
  var leftWidth:Number;
  var rightWidth:Number;

  override function doLayout():Void {
    for (node in getManaged(content)) {
      if (node.id == "top") {
        topHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, 0);
      }
      else if (node.id == "bottom") {
        bottomHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, height - bottomHeight);
      }
      else if (node.id == "left") {
        leftWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, 0, topHeight);
      }
      else if (node.id == "right") {
        rightWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, width - rightWidth, topHeight);
      }
      else if (node.id == "center") {
        setNodeWidth(node, width - (leftWidth + rightWidth));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, leftWidth, topHeight);
      }
    }
  }
  override function getPrefWidth(height:Number):Number {
    return width;
  }
  override function getPrefHeight(width:Number):Number {
    return height;
  }
}

Here is a code example of using the BorderLayout shown above.

/*
 * ContainerSubclassLayoutExample.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import containersubclasslayoutexample.layout.BorderLayout;

var nodes = [
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
  Button {
    text: "Center"
    id: "center"
  }
];

Stage {
  var sceneRef:Scene;
  title: "Container Subclass Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      BorderLayout {
        width: bind sceneRef.width
        height: bind sceneRef.height
        content: nodes
      }
    ]
  }
}

Lastly, here is an example of defining the BorderLayout custom layout functionality using the second way listed above, which is to create a Panel instance and override its behavior:

/*
 * PanelLayoutExample.fx -
 * Example of using a Panel to create a custom layout
 */

package panellayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

var nodes = [
  Button {
    text: "Center"
    id: "center"
  },
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
];

Stage {
  var panel:Panel;
  var sceneRef:Scene;
  title: "Panel Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      panel = Panel {
        var topHeight:Number;
        var bottomHeight:Number;
        var leftWidth:Number;
        var rightWidth:Number;
        content: bind nodes
        width: bind sceneRef.width
        height: bind sceneRef.height
        onLayout: function():Void {
          for (node in getManaged(panel.content)) {
            if (node.id == "top") {
              topHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, 0);
            }
            else if (node.id == "bottom") {
              bottomHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, panel.height - bottomHeight);
            }
            else if (node.id == "left") {
              leftWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, 0, topHeight);
            }
            else if (node.id == "right") {
              rightWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, panel.width - rightWidth, topHeight);
            }
            else if (node.id == "center") {
              setNodeWidth(node, panel.width - (leftWidth + rightWidth));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, leftWidth, topHeight);
            }
          }
        }
        prefWidth: function(height:Number):Number {
          return panel.width;
        }
        prefHeight: function(width:Number):Number {
          return panel.height;
        }
      }
    ]
  }
}

To learn more about using and creating layouts in JavaFX 1.3, see the blog posts that Amy Fowler has been writing on the subject, and the Custom Layouts chapter in the upcoming new edition of the Clarke/Bruno/Connors JavaFX book.

A note regarding the JavaFX RIA Exemplar Challenge: We have received several entries and I’m in the process of packaging them up and sharing them with the judges.  The winner will be announced in early June, 2010.

Regards,

Jim Weaver


Go to Source

Reminder: RIA Exemplar Challenge Deadline is 22-May-2010 0

Its-the-ux-stupid-small Just a quick reminder that the RIA Exemplar Challenge deadline is 22-May-2010.  The Mötley Judging Crüe is looking forward to seeing your entry!

Regards,

Jim Weaver

Go to Source

Reminder: RIA Exemplar Challenge Deadline is 22-May-2010 0

Its-the-ux-stupid-small Just a quick reminder that the RIA Exemplar Challenge deadline is 22-May-2010.  The Mötley Judging Crüe is looking forward to seeing your entry!

Regards,

Jim Weaver


Go to Source

EarthCubeFX on JavaFX-TV 0

The previous blog post provided an example, named EarthCubeFX, of creating a 3D application with JavaFX 1.3.  

Earthcubefx-tv
 

Today's post highlights Oracle JavaFX engineer and author Jim Clarke's experience running EarthCubeFX on JavaFX-TV.  To quote Mr. Clarke:

The tag line is "JavaFX: Bringing Rich Experiences to All the Screens of Your Life", so I decided to put it to the test. Jim Weaver created a 3D demo called  EarthCubeFX, and I wanted to know what needed to be done for it to run on a true JavaFX-TV platform.  Luckily, I had just obtained an Intel Canmore CE3100 system that runs JavaFX-TV.

Obviously, the TV does not have a mouse, so the first thing I had to do is use some of the keys on the remote control to invoke the same behavior that the mouse buttons activated in Jim's original code.  The JavaFX-TV runtime maps the remote control keys to JavaFX KeyEvent objects. The first choice was to decide which keys to use for the pitch and roll rotations; the remote's arrow keys  were the obvious choice. I arbitrarily picked the CHANNEL_UP and CHANNEL_DOWN keys to do the Z translation, which moves the cube further back or forward in the field of view. Lastly,  I used the OK key to take the cube back to its home position.  I only added 8 lines of code, compiled the application in NetBeans using the JavaFX-TV Emulator, then copied the Jar file over to the Canmore and ran it as shown in the video. The Google map tile images are still fetched over the Internet. The animation, and 3D features, run exactly as on the desktop.

Here's a short video that Jim Clarke created of EarthCubeFX running in JavaFX-TV on the Canmore set-top box:

Also, here is the code that Jim Clarke added to handle remote controller keys:

  public function keyRotation(ke: KeyEvent) : Void {
    if (ke.code == KeyCode.VK_RIGHT) {
      angleY++;
    }
    else if (ke.code == KeyCode.VK_LEFT) {
      angleY--;
    }
    else if (ke.code == KeyCode.VK_UP) {
      angleX--;
    }
    else if (ke.code == KeyCode.VK_DOWN) {
      angleX++
    }
    else if (ke.code == KeyCode.VK_CHANNEL_UP) {
      translateZ -= 10;
    }
    else if (ke.code == KeyCode.VK_CHANNEL_DOWN) {
      translateZ += 10;
    }
    else if (ke.code == KeyCode.VK_ENTER) {
      goHomePosition();
    }
  }

Thanks, Mr. Clarke!  Also, remember that the deadline for RIA Exemplar Challenge entries is 22-May-2010 so please submit it if you haven't already!

Regards,

Jim Weaver

Go to Source

EarthCubeFX on JavaFX-TV 0

The previous blog post provided an example, named EarthCubeFX, of creating a 3D application with JavaFX 1.3.  

Earthcubefx-tv
 

Today’s post highlights Oracle JavaFX engineer and author Jim Clarke’s experience running EarthCubeFX on JavaFX-TV.  To quote Mr. Clarke:

The tag line is “JavaFX: Bringing Rich Experiences to All the Screens of Your Life”, so I decided to put it to the test. Jim Weaver created a 3D demo called  EarthCubeFX, and I wanted to know what needed to be done for it to run on a true JavaFX-TV platform.  Luckily, I had just obtained an Intel Canmore CE3100 system that runs JavaFX-TV.

Obviously, the TV does not have a mouse, so the first thing I had to do is use some of the keys on the remote control to invoke the same behavior that the mouse buttons activated in Jim’s original code.  The JavaFX-TV runtime maps the remote control keys to JavaFX KeyEvent objects. The first choice was to decide which keys to use for the pitch and roll rotations; the remote’s arrow keys  were the obvious choice. I arbitrarily picked the CHANNEL_UP and CHANNEL_DOWN keys to do the Z translation, which moves the cube further back or forward in the field of view. Lastly,  I used the OK key to take the cube back to its home position.  I only added 8 lines of code, compiled the application in NetBeans using the JavaFX-TV Emulator, then copied the Jar file over to the Canmore and ran it as shown in the video. The Google map tile images are still fetched over the Internet. The animation, and 3D features, run exactly as on the desktop.

Here’s a short video that Jim Clarke created of EarthCubeFX running in JavaFX-TV on the Canmore set-top box:

Thanks, Mr. Clarke!  Also, remember that the deadline for RIA Exemplar Challenge entries is 22-May-2010 so please submit it if you haven’t already!

Regards,

Jim Weaver


Go to Source

Next Page »