Showing posts with label javafx. Show all posts
Showing posts with label javafx. Show all posts

October 16, 2009

A mayan calculator

The JFXStudio blog launched its second coding challenge. This month's challenge is to write an interesting application in no more than 30 lines of code in the theme: "five".

At first, I didn't think I was going to enter because I thought I wouldn't have the time for it, but I found some time and started doing a little research into the subject "five". So I looked "five" up in Wikipedia. There, I learned about the quinary numeral system (base-5) and that many languages use it. And apparently, the Mayas used a quinary system as well. That's when I decided I would make a Mayan calculator and with that enter this month's challenge.

I am finished, have e-mailed my 30-line app to Joshua, and yet again, amazed at how powerful JavaFX is. I was able to write a pretty good looking and functional application in just 30 lines of code. Click on the screenshot below to start the application (the source for the picture of the Mayan Ruin is http://www.themayantraveler.com).

October 08, 2009

I won the JFXStudio challenge of september 2009!

Last Sunday, Joshua Marinacci announced the winner of September's JFXStudio JavaFX coding challenge. Now, guess who won. Yes, me!

The challenge was to write an interesting application in just 30 lines of code (or 3000 characters), in the theme "time". Most submissions were clocks of some sort, and so was mine. I don't know what made me came up with the idea for a pacman clock, but I did, and it made me win the challenge too!

I have tried to stuff as much interesting behavior in my clock as I could while staying within those 30 lines of code.

Here are some of the tricks to pull that off:

  • Against all sound coding principles, I used lots of cryptic, one letter variables and functions with really short names (like "lz" for "leading zeros", and now I am reading back my code, I could have made it even more compact if I had defined a function "r" for invoking Math.random),
  • so, it is a good thing I also used this important object orientation principle to keep things compact and be able to create autonomously haunting ghosts: encapsulation
  • I used a constant named "forever" in stead of Timeline.INDEFINITE for all the TimeLine instances used in the application,
  • I used SVGPaths, which are a bit cryptic, but very compact,
  • I avoided typing spaces and carriage returns as much as I could,
  • and I tried not to care too much about code readability (which, for a Java developer like me, is a very hard thing to do).
So, as you can see, I squeezed JavaFX as much as I could, and out comes a fun to watch little clock. My kids love to watch it!

You can webstart the pacman clock here, and you can download the source code to see if you can make any sense of it (I know I won't be able to after a year or so) here.

This challenge was a lot of fun! Hopefully, I will find some spare time to enter next month's challenge. This time, we are challenged to write a 30 line (or 3000 char) app again but now in a different theme: "five". Let's see, what can I make of that...

five
alive
hive
jive
live
strive
drive
...


November 09, 2008

TweetBox preview release

The title sounds more official then I intend to, but I guess this what I should call it. I don't even have a versioning scheme for TweetBox. I still see it as a toy project. On the other hand, the TweetBox is taking nice shapes. Programming JavaFX turns out to be a lot of fun, and once you get the hang of it, it is pretty easy too. Imho, java developers now finally have a sophisticated GUI API that is productive (Swing is rather counter-productive, and that's coming from a faithfull fan) and easy to use. JavaFX still has quite a way to go before it becomes as sophisticated as Adobe Flex and AIR, but still. A big pro of JavaFX is that the syntax of the language allows you to build GUI's declaratively (just like Flex's MXML) and that it is very neat and clean. Compared with JavaFX, MXML is definitely more cumbersome.

You can download the binaries for TweetBox here. Simply unzip it somewhere and double click TweetBox.jar (or run "java -jar TweetBox.jar" on the command line). Mind you, it still misses lots of functions that we take so much for granted in tools such as Twhirl, such as sending updates, replies and direct messages, retweeting, following/unfollowing people, et cetera. I have now come to appreciate them even more.

For the time being, configuration of your twitter login credentials must be done through a properties file (here's an example), that you must place in your user home folder (you can figure out the location of that folder yourself, I just use the value of the java system property "user.home").

TweetBox sometimes crashes rather spectacularly every once in a while at startup. That has something to do with the fact that I am using a separate thread for invoking the Twitter API. Also, it is not yet getting your friend timeline at regular intervals. The button with the binoculars allows you to do a twitter search. It will only get 20 results, but it works.

I have only tested TweetBox on Vista, so let me know the results of using it on other platforms.

In short, TweetBox is unstable and misses lots of features, but admit it, the way it fades in on your desktop when you start the TweetBox, it's nice shapes and that you can see through it is awesomely cool.

November 07, 2008

TweetBox progress

I have received a few cheers (thanks Lee and Rick), so I continued my hobbying with JavaFX. I am now really getting the hang of JavaFX. This fall, version 1.0 of the JavaFX SDK will be released. I can't wait, because many things in the preview release that I currently using are a bit cumbersome.

It also misses some rather essential GUI building blocks, such as a scroll view. So, I had to build one myself (I used James Weaver's TableNode class as the basis). I also had to write a new Text node that can wrap text. I had to do some very ugly AWT tricks to pull that off.

The current application still is very dumb, but it works rather well. I will next have to implement some config screens and have the tweetbox get tweets at a configurable interval.

At some point, I think I will decide to make this all open source on code.google.com, so you can all look at the code and see how it is done.

In any case, here's a new screenshot (some of you should recognize the color scheme):


November 02, 2008

Teaching myself JavaFX by building a Twitter client

I am playing with the JavaFX Preview SDK to see what it does and feels like. I am using Netbeans 6.1. So far, I think I like it, although it takes some time to get used to the JavaFX syntax. It looks like java and underneath it is java, but you need a different mindset to use it.
The preview SDK is missing several things as it seems. Maybe I am using the wrong distribution.

To teach myself JavaFX I needed a goal. Something simple and fun to build. I decided on a Twitter client. Using much of James Weaver's (check out his blog, it is worth your while if you want to learn JavaFX) example code, I have cobbled together a very crude Twitter thingy that can only read my own friend timeline (or the public timeline), but I have gotten this far without too much effort.

Here's a screenshot:



Of course, I will never finish it, because I perpetually lack time. Cheering me on might help.