
Courtesy Scott Adams
JavaFX 1.2 was released quite recently as of this blog post. One of the latest new features to the JavaFX scene-graph are charts!
Despite the humorous commentary in the cartoon, charts really are useful to businesses because they make it easier to visualize and therefore analyse trends in data.
Memory Monitor Program
Here is a demonstration of a program designed to track memory usage:
Here is the source code for the program.
This program calculates memory usage from the java.lang.Runtime class's getMaxMemory(), getTotalMemory(), and getFreeMemory() methods, converting them to Megabytes due to the sheer number of bytes. It then outputs it to the graph:
- //Load total memory into the chart.
- insert LineChart.Data {
- xValue: time
- yValue: runtime.totalMemory() / 1000000
- } into memoryChartSeries[0].data;
- //Load the used memory into the chart.
- insert LineChart.Data {
- xValue: time
- yValue: (runtime.totalMemory() - runtime.freeMemory()) / 1000000
- } into memoryChartSeries[1].data;
and puts the proportions to the Pie Chart once every ten seconds:
- pieChart.data[0].value = (runtime.totalMemory() - runtime.freeMemory()) / 1000000;
- pieChart.data[1].value = runtime.freeMemory() / 1000000;
- pieChart.data[2].value = (runtime.maxMemory() - runtime.totalMemory()) / 1000000;
Additionally, you can add ImageView objects to see how much memory use increases.
Though the program's layout isn't very pretty, you could theoretically use this program to check for memory leaks. For instance, it's obvious that each time this program updates the pie chart, more and more memory is consumed, which is why I wrote it to refresh only every 10 seconds (it still uses up all memory available to it if you run it long enough). Ah, the irony!
JavaFX 1.2
Overall, JavaFX 1.2 is a great improvement over the previous versions. There are still a few features I would like to see in the future.
For instance, it would be helpful to be able to access media and video through streams. At the present time, they can only be loaded into JavaFX by means of a URL, which decreases flexibility quite a bit. It would be very convenient to be able to store media and images with the Storage class, as these files tend to be too large to efficiently save inside the program's jar file, and the file structure of different operating systems can vary. But alas, the Storage class can only be correctly accessed by streams (a "hack" to work around this limitation would make it system-specific).

It would also be nice if a more advanced collision detection and response system could be added. At the moment, one can detect collisions through a node's bounds. However, these bounds are based upon rectangles, thereby decreasing accuracy as one can infer from the figure to the left.
It is also a bit difficult to replicate the appearance of an old fashioned swing GUI, though that is mainly due to the lack of a visual designer, which thankfully is due to arrive in the near future.
The good news is that this version now includes Linux support, and other features I am eagerly awaiting are due to arrive in the near future.
