Tags

Blogroll
My Photos
www.flickr.com
This is a Flickr badge showing items in a set called Recent. Make your own badge here.

Our Java Podcast

Favorite Sites

Archives
« December 2009
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today
Click me to subscribe
Search


Navigation
 

Today's Page Hits: 16

Sunday Sep 28, 2008
Learning JavaFX - Getting Started by Reversing Time

I knew my best path to learning JavaFX and creating my countdown timer app would be to study one of the existing sample applications. The stopwatch example seemed perfect, as it contained basic timer logic (though counting up and not down) and had both a digital and clock-style display. First though, I stopped by javafx.com and downloaded the JavaFX Preview SDK so I'd have all the runtime components and NetBeans IDE. I then grabbed the stopwatch example, installed it as a project in NetBeans, and started examining the code.

The file structure of the project helped me get a feel for what I needed to do, though the terminology was unfamiliar. A short main program (Main.fx) created a "Frame" and populated it with a StopwatchWidget. Looking next at StopwatchWidget.fx I saw it created a customized "Node" with a "Model" called StopwatchModel and a "Theme" called LightTheme. StopwatchModel.fx contained all the timer logic and functions to start, stop, and reset the stopwatch. LightTheme.fx contained all the code to render the user interface - stopwatch face, hands, dial markings, start/stop buttons, etc.. It extended an overall "Theme", which I found in Theme.fx, not surprisingly and discovered there was an alternative DarkTheme in DarkTheme.fx.

I wanted to get started by reversing the timing function so the stopwatch counted down and not up, so dug into StopwatchModel.fx. Reversing the rotation of the timer hands was easy enough but that didn't mean I was counting down. However, since JavaFX lets me mix JavaFX Script and Java I could splice in the Java code from my previous countdown timer both to calculate milliseconds remaining until the target date/time and to extract from that values for the days, hours, minutes, and seconds remaining so I could update the digital display. In doing so I learned a few things:

At this point, though, I had converted my timer logic into JavaFX inside StopwatchModel to produce:

private attribute targetString:String = "2009-03-27-8-0"
private attribute targetMilliseconds:Number = 0;

private attribute timerListener:ActionListener = ActionListener {
public function actionPerformed(evt:ActionEvent): Void {
    if (targetMilliseconds == 0) {
        var formatter:SimpleDateFormat = new SimpleDateFormat("yyyy-M-d-k-m");
        var date:Date = formatter.parse(targetString);
        targetMilliseconds = date.getTime();              
    }
    var now:Integer = System.currentTimeMillis() as Integer;
            
    var nn:Number = System.currentTimeMillis() as Number;
        var n:Integer = ((targetMilliseconds - nn)/1000) as Integer;
        if (n > 0) {
            var s:Integer = n mod 60;
            var m:Integer = n / 60;
            var h:Integer = m / 60;
            var d:Integer = h / 24;
            h = h mod 24;
            m = m mod 60;

            timeString = "{%03d d}-{%02d h}:{%02d m}.{%02d s}";
        }
        else {
            timeString = "000-00:00.00";
        }
    }
}
This gave me the ability to count down properly and set the right value in the magical global timeString, but I clearly couldn't map this to the digital display of the stopwatch much less the moving hands. That meant serious modification to the user interface, which I'll cover in my next blog entry.
Posted at 06:05PM Sep 28, 2008 by David Bryant in General  | 
Tags:  java software

Thursday Sep 18, 2008
Learning JavaFX

This past weekend I got started on my personal project to learn programming in JavaFX. While I am a Marketing Guy by day I spent a lot of years as a software engineer and my career is founded far more on C programming than B School. I've explored basic Java plus tinkered with a variety of scripting languages. I figured I'd be a good novice test case for JavaFX Script and its powerful graphics and media capabilities.

Getting started was easy enough as everything you need -- the Preview SDK, sample programs, and API documentation -- is available via javafx.com. The NetBeans IDE makes it easy to create a JavaFX project and begin editing .jx files.

So what to build? Deciding on my first JavaFX app was easy. Just prior to JavaOne this year I used NetBeans to create in Java a countdown timer I could use to remind us all how many (or how few) days remained before the start of JavaOne. Obviously I needed to craft a JavaFX version of that same countdown app to use for this year. (And yes, we are already well into the planning for JavaOne 2009.)

I went from initial download of the JavaFX Preview SDK to completion of the JavaFX countdown timer app in two evenings. It was easy, fun, and I learned quite a lot. NetBeans and a couple of JavaFX sample applications were tremendously valuable, along with the API docs on javafx.com.

A screen snapshot of my completed application is at the top of this blog entry. Over the course of a few more entries I'll talk about the development experience and my observations about JavaFX Script. What I can say for now is that ease with which I built my first application has me convinced that JavaFX will let me do something I couldn't have done before -- create Rich Internet Applications for desktop, mobile, and TV. I can't wait!

Posted at 10:47PM Sep 18, 2008 by David Bryant in General  | 
Tags:  java software

Friday May 04, 2007
Pidgin 2.0 is here -- Gaim is now Pidgin

The long awaited, even longer in beta 2.0 release of gaim, my personal favorite multi-protocol instant messaging client, is now here. However, it's no longer called "gaim" thanks to some naming concerns raised by AOL. Happily an agreement with AOL has made possible the 2.0 release though required a name change. The new name is "pidgin", which is clever and should send you to a dictionary to appreciate the etymology.

Pidgin 2.0 has a nicer look and feel than gaim though is still very simple, clean, and space efficient. Email alerts are much more seamlessly implemented and file transfer seems to finally work. It's blissfully free of advertising, bloatware, and links to other sites I don't want or use. Pidgin is great for managing connections to multiple IM services across multiple accounts which I do all the time, what with having personal accounts for family and friends as well as work accounts for colleagues all via several servers (including our corporate system based on Sun Java System Instant Messaging).

Pidgin is free and a thriving open community project. Source code is available if you like, and is intended for use on Windows and UNIX. I'm quite happy with the new version. Check out the Pidgin project page if you'd like to know more or take pidgin for a test drive.

Posted at 10:07PM May 04, 2007 by David Bryant in General  | 
Tags:  software

Monday Apr 30, 2007
Things I Am Waiting For

There are a number of things on the web I'm trying to keep an eye out for so I'll know when they arrive:

Posted at 08:06PM Apr 30, 2007 by David Bryant in General  | 
Tags:  gizmos software