JavaFX Talk for RJUG
Jan 15, 2009 in Work
This Tuesday I presented on the JavaFX technology to the Rochester Java User Group. It was a lot of fun to do a technical presentation again – it’s been a long time since I spoke on technical stuff. Dave Cok of RIT brought his compiler class to the presentation. That was a little daunting – language theory is not my strongest side – but was very motivating as well.
I used my pet project to talk about how one might migrate a Java project to JavaFX and how to mix Java code and JavaFX code. I have been rewriting Bahamontes in JavaFX and named that project “Anquetil” to stay with the theme (this reminds me that should upload what I’ve been doing with Bahamontes since July ‘07). In order to get the Anquetil work in a state to fit my talk it was a mad scramble during the weekend and Monday. It also became a time scramble because I stared myself blind on two programming mistakes: situations where you know that it is something simple that you have done wrong in the code but you’re just not seeing it. I entertained the audience with them, and here they are for your delight as well.
The first code snippet (why do I get null pointer exceptions during runtime!?):
public class Mapping extends JPanel {
public void Mapping() {
myLayout();
mapClient = new Exec();
}
private void myLayout() {
setLayout(new BorderLayout());
setPreferredSize(new Dimension(1000, 450));
JLabel mapLabel = new JLabel();
mapLabel.addMouseListener(
new MouseAdapter() {
public void mousePressed(MouseEvent evt){
mapLabelMousePressed(evt);
}
});
add(mapLabel, BorderLayout.CENTER);
}
private Exec mapClient;
}
And the second (why is the calendar component not showing on the screen in the way I want!?):
public class MyCalendar extends JXMonthView {
public MyCalendar(final RideData parent) {
datePicker = new JXMonthView();
datePicker.setShowLeadingDates(true);
datePicker.setShowTrailingDates(true);
datePicker.setTraversable(true);
addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent evt) {
parent.dateChanged(getSelectedDate());
}
});
datePicker.setFlaggedDates(parent.getFlaggedDates());
datePicker.setSelectedDate(
new Date(parent.getFlaggedDates()[0]));
datePicker.commitSelection();
}
private JXMonthView datePicker;
}
Anyways, onto JavaFX. Sun released version 1 of JavaFX on December 4. The technology makes it much easier to create media-rich applications that run on desktops, laptops, in browsers, on cell phones, settop boxes, Bluray players and so forth. With the new plug-in in Java SE 6U10 applets are much more powerful, can interact with JavaScript and with CSS stylesheets, and you can drag them out of the browser.
The part of my own talk that I enjoyed the most was discussing the JavaFX Script language. It has a number of features that enable you to write very efficient code such as “bind”, “on replace” and the operations you can do on sequences. The language has a concept of time (it knows what seconds, milliseconds, minutes and so on are), transformations, interpolations making it very easy to do animations. We examined the source code of some of the samples that come with Netbeans 6.5 and did things like “what happens if you remove ‘bind’ from that statement?”
References:
- The JavaFX website: http://javafx.com
- Get Netbeans 6.5 with the JavaFX SDK: http://netbeans.org
- The new plug-in: http://java.com
- Language tutorial: http://java.sun.com/javafx/1/tutorials/core/
- API reference: http://java.sun.com/javafx/1/docs/api/
- Josh Marinacci’s blog: http://weblogs.java.net/blog/joshy/
