advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : JavaFX: Learning by Example :

Class #1: The Frame


Figure 2. The application background.

Before anything can be displayed, you will need a frame, like a Swing Frame. JavaFX offers complete support for Swing components and is much more easy to use in comparison with Java Swing. It's easy to set the frame attributes: dimensions, location, title, and visibility. It's also simple to specify the window content by using a simple Canvas (a Swing component from JavaFX) and an intuitive content attribute. Between brackets and separated by comma, you can specify all the graphical components that you want displayed on the Canvas. Because you want to have a scrollable frame, everything is inserted into a ScrollPane. Listing 1 shows the main class of the application, named mariahcarey.fx.

Class #2: The Background Animation

Now it's time to develop the first graphical component of the application. To do so, you need to know that a defined graphical component is a JavaFX class, which extends the CompositeNode class and implements the composeNode() operation. Here's a common example of writing graphical components:
class your_class extends CompositeNode {
//declaring attributes and operations
}

//initialize attributes
//definig operations

function your_class.composeNode() = 
Group {
…
Note: The Group class is used to unify more graphical components so they can act as one. When applying an effect to a Group, the graphical components of the Group are viewed as an entity. There are also Groups that function as containers that have their own coordinate systems and are not visible.

If you look carefully at first page of Mariah Carey site, you will notice that the big picture of her (from the center) is replaced from time to time with other pictures, creating a nice effect on a static background. With JavaFX capabilities (and the right pictures), it's very easy to simulate that animation. A combination of three elements provides such great animations:

  1. The opacity Attribute: This attribute takes a value between 0.0 (minimum opacity) and 1.0 (maximum opacity) and it represents the opacity degree of a graphical component. You can create a disappear/appear effect by covering the [0.0, 1.0] interval with the intermediate values and a time delay.
  2. The dur(ation) Operator: This is a cool operator you can use to asynchronously apply an array to a time interval. The time is specified in milliseconds. There are four types of interpolations over the interval:

    • linear
    • easein
    • easeout
    • easeboth
  3. The bind Operator: This operator obtains an automatic update of the object that contains the attribute evaluated by bind. This update will take place every time the value of the attribute is changed by bind. This creates a lazy, incremental feel. Of course, the bind can also be used with constant values, but in that case, it has no effect.
Combining the power of these three elements leads to amazing animations and effects. Because you will use this for developing an images animation, you have to know how to load an image in JavaFX. The ImageView class accomplishes this in the same scripting manner. For example, to load the background image for the sample application, you would code something like this:
ImageView {
          transform: []
          image: Image 
		  { url: "{__DOCBASE__}//images//background.bmp" }
          }
Note: The __DOCBASE__ is used to get the current directory.

In this case, the animation takes place at every mouse click. The mouse click event is represented by the onMouseClicked operation. JavaFX supports seven kinds of events:

  • onMouseClicked;
  • onMouseMoved;
  • onMousePressed;
  • onMouseExited;
  • onMouseEntered;
  • onMouseReleased;
  • onMouseDragged;
Here's an example of the onMouseClicked event:
onMouseClicked: operation(e:CanvasMouseEvent) {              
            …
            }
Now that you've got all the theoretical information, all you need is to put it together to create the first graphical component of this application. This class is named Bk_end.fx (shown in Listing 2).

Home / Articles / JavaFX: Learning by Example / 1 / 2 / Next Page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 34
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

IBM Brings Developers Into the Cloud
Apache at 10: You Can't Buy Us
Microsoft's CodePlex Foundation Moving Forward
Apple Claims 100,000 Apps, Google Analyzes Them
Nokia Latest to Play Opera Mobile 10 Browser
PayPal Opens Up Payment Platform to Devs
Ubuntu Linux 9.10 'Karmic Koala' Starts Its Climb
IBM Links Rational Developer Tools, Tivoli Apps
Libraries Give Vista Apps a Windows 7 Look
Ubuntu: The 'Default Alternative' to Windows?

Delivering Web-based Embedded Fonts in CSS 3
Adobe Helps PHP Developers Create Rich Internet Applications
Java Developers Finding a Home at Adobe Flex
Virtualization Delivers a Dynamic Infrastructure
Consuming XML Web Services in iPhone Applications
Build a More Agile Business with IBM
POJO-Based Solutions for LDAP Access: One Good, One Better
IBM Offers Enhanced Measurement and Management for Energy Usage
IBM Helps Transformation to an Information-Based Enterprise
Top Five Touch UI-Related Design Guidelines

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs