Calculator Widget

By Rakesh Menon, December 8, 2008

This sample demonstrates how to write simple Calculator widget using Common Profile APIs. The widget can be executed as standalone application, in browser and mobile. The widget can be dragged onto desktop. Use Alt + Left click + Drag to drag the applet out of browser.

Understanding the Code

The Key class is javafx.scene.CustomNode which has a Rectangle and Text. The background of rectangle is filled with LinearGradient. The pattern of gradient is changed when mouse enters the node. Its restored on exit.

A sequence of Key is created to form the calculator user interface. Each key has a unique code. This code is used for determining the operation performed by the code. Respective operations are performed on key press. Use arrow keys for navigating across keys. Use enter key to perform the operation of selected key.

References