12.01.2013 Views

JavaFX in Action - Manning Publications

JavaFX in Action - Manning Publications

JavaFX in Action - Manning Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2 CHAPTER 1 Welcome to the future: <strong>in</strong>troduc<strong>in</strong>g <strong>JavaFX</strong><br />

although some computers offered the luxury of hardware sprites. For the programmer,<br />

the simple act of pok<strong>in</strong>g values <strong>in</strong>to RAM gave <strong>in</strong>stant visual gratification.<br />

These days th<strong>in</strong>gs are a lot more complicated; we have layers of abstraction separat<strong>in</strong>g<br />

us from the hardware. Sure, they give us the wonders of scrollbars, rich text editors,<br />

and tabbed panes, but they also constra<strong>in</strong> us. The World Wide Web raised the<br />

bar; users now expect glossier visuals, yet the graphical toolkits used to create desktop<br />

software are little evolved from the days of the first Mac<strong>in</strong>tosh or Amiga.<br />

But it’s not just the look of software that has been changed by the web. Increas<strong>in</strong>gly<br />

data is mov<strong>in</strong>g away from the hard disk and onto the <strong>in</strong>ternet. Our tools are also start<strong>in</strong>g<br />

to move that way, yet the fledgl<strong>in</strong>g attempts to build onl<strong>in</strong>e applications us<strong>in</strong>g HTML<br />

and Ajax have resulted <strong>in</strong> noth<strong>in</strong>g more than pale imitations of their desktop cous<strong>in</strong>s.<br />

At the same time, consumer devices like phones and TV set top boxes are gett<strong>in</strong>g<br />

<strong>in</strong>creas<strong>in</strong>gly sophisticated <strong>in</strong> terms of their UI, and faster wireless networks are reach<strong>in</strong>g<br />

out to these devices, allow<strong>in</strong>g applications to run <strong>in</strong> places previously unheard of.<br />

If only there were a purpose-built tool for writ<strong>in</strong>g the next generation of <strong>in</strong>ternet<br />

software, one that could serve up the same rich functionality of a desktop application,<br />

yet with drop-dead-gorgeous visuals and rich media content with<strong>in</strong> easy reach, delivered<br />

to whatever device (PC, television, or smart phone) we wanted to work from today.<br />

Sound too good to be true? Let me <strong>in</strong>troduce you to <strong>JavaFX</strong>!<br />

1.1 Introduc<strong>in</strong>g <strong>JavaFX</strong><br />

<strong>JavaFX</strong> is the name of a family of technologies for develop<strong>in</strong>g visually rich applications<br />

across a variety of devices. Version 1.0 was launched <strong>in</strong> December 2008, focus<strong>in</strong>g on<br />

the desktop and web applets. Version 1.1 arrived a couple of months later, add<strong>in</strong>g<br />

phone support to the mix, and by summer 2009 version 1.2 was available, sport<strong>in</strong>g a<br />

modern UI toolkit. Later editions promise to expand the platform’s reach even further,<br />

onto TV devices, Blu-ray disc players, and possibly even personal video recorders,<br />

plus further enhance its desktop support with more next-gen UI controls.<br />

The <strong>JavaFX</strong> APIs have a radically different way of handl<strong>in</strong>g graphics, known as reta<strong>in</strong>ed<br />

mode, shift<strong>in</strong>g focus away from the pixel-push<strong>in</strong>g immediate mode (à la the Java2D library<br />

used by Sw<strong>in</strong>g), toward a more structured approach that makes animation cleaner and<br />

easier. At <strong>JavaFX</strong>’s center is a major new programm<strong>in</strong>g language, <strong>JavaFX</strong> Script, built<br />

from the ground up for model<strong>in</strong>g and animat<strong>in</strong>g multimedia applications. <strong>JavaFX</strong><br />

Script is compiled and object oriented, with a syntax <strong>in</strong>dependent of Java but capable<br />

of work<strong>in</strong>g with Java class files. Together <strong>JavaFX</strong> Script (the language) and <strong>JavaFX</strong> (the<br />

APIs and tools) create a modern, powerful, and convenient way to create software.<br />

1.1.1 Why do we need <strong>JavaFX</strong> Script? The power of a DSL<br />

A very good question: why do we need yet another language? The world is full of programm<strong>in</strong>g<br />

languages—wouldn’t one of the exist<strong>in</strong>g languages do? Perhaps JavaScript,<br />

or Python, or Scala? Indeed, what’s wrong with Java? Certa<strong>in</strong>ly <strong>JavaFX</strong> Script makes<br />

writ<strong>in</strong>g slick graphical applications easier, but is there more to it than that?<br />

What makes graphics programm<strong>in</strong>g such an ill fit for modern programm<strong>in</strong>g<br />

languages? There are many problems; ask a dozen experts and you’ll get

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!