DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Using the Java Deployment Toolkit with JavaFX Applets

Using the Java Deployment Toolkit with JavaFX Applets

James Weaver user avatar by
James Weaver
·
Sep. 25, 08 · Java Zone · Interview
Like (0)
Save
Tweet
13.19K Views

Join the DZone community and get the full member experience.

Join For Free

first, let me apologize for resurrecting the very humble javafx program shown below, but i want to keep this example very succinct.  this will enable you to use it as "starter code" for javafx applet deployment.  note: to see more functional javafx programs, please see articles in the jfx custom nodes category .

bindtofunctionapplet_sdk_preview

note: thanks to reader "mbien" for pointing out that the colors of the original applet in this post were hideous (my words).  i then consulted graphics designer mark dingman of malden labs who gave me a graphical mock-up from which i created the above applet. here's the code for this applet, updated for the javafx sdk preview:

/*
* bindtofunctionapplet.fx - a compiled javafx program that demonstrates
* how to create javafx applets.
* it also demonstrates binding to a function.
*
* developed 2008 by jim weaver (development) and mark dingman (graphic design)
* to serve as a javafx script example.
*/
package com.javafxpert.bind_to_function;

import javafx.application.*;
import javafx.ext.swing.*;
import javafx.scene.*;
import javafx.scene.geometry.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import javafx.scene.transform.*;
import java.lang.math;

class circlemodel {
attribute diameter:integer;

bound function getarea():number {
math.pi * math.pow(diameter / 2, 2);
}
}

application {
var cmodel = circlemodel {};
var componentviewref:componentview;
var stageref:stage;
stage:
stageref = stage {
var labelfont = font {
name: "sans serif"
style: fontstyle.plain
size: 32
}
fill:
lineargradient {
startx: 0.0
starty: 0.0
endx: 0.0
endy: 1.0
stops: [
stop {
offset: 0.0
color: color.rgb(0, 168, 255)
},
stop {
offset: 1.0
color: color.rgb(0, 65, 103)
}
]
}
content: [
circle {
centerx: 250
centery: 250
radius: bind cmodel.diameter / 2
fill:
lineargradient {
startx: 0.0
starty: 0.0
endx: 0.0
endy: 1.0
stops: [
stop {
offset: 0.0
color: color.rgb(74, 74, 74)
},
stop {
offset: 1.0
color: color.rgb(9, 9, 9)
}
]
}
},
text {
font: labelfont
x: 30
y: 70
fill: color.black
content: bind "diameter: {cmodel.diameter}"
},
text {
font: labelfont
x: 260
y: 70
fill: color.black
content: bind "area: {%3.2f cmodel.getarea()}"
},
componentviewref = componentview {
transform: bind
translate.translate(40, stageref.height - 30 -
componentviewref.getheight())
component:
slider {
minimum: 0
maximum: 400
preferredsize: bind [stageref.width - 80, 20]
value: bind cmodel.diameter with inverse
}
}
]
}
}

why use the java deployment toolkit for java applets?

according to sun's java deployment toolkit overview page , " desktop clients have a wide variety of java platforms installed, from the microsft vm to sun's latest java se 6 updates. they run various operating systems from sun, microsoft, apple, red hat, and others, and are connected to the internet at a wide range of connection speeds. how are content providers to deliver java content to all of these clients with the best possible user experience?

various sources have published javascript techniques for detecting and deploying the java platform for use by java plug-in applets and java web start applications. these scripts generally have serious limitations and fail to support the varied combinations of browser, os, and configuration options found on today's clients.

the java deployment toolkit allows developers to easily deploy applets and applications to a large variety of clients with javascripts. it also provides advice on using some of the most powerful features available in java web start and java plug-in, and an outline of the differences between these two deployment vehicles.
"

in a nutshell, the java deployment toolkit is a javascript library maintained by sun and always available at runtime by your html code.  this library has several methods that perform tasks such as sensing java-related infrastructure and installing the jre on client machines.  we'll use one of these methods, namely runapplet , to run a javafx applet with a specified minimum jre version.  here's the html and javascript code i'm using to deploy today's example applet:

<html>
<script src="http://java.com/js/deployjava.js"></script>
<script>
var attributes = {codebase:'http://jmentor.com/jfx/bindtofunctionapplet',
code:'javafx.application.applet.class',
archive:'bindtofunctionapplet.jar, javafxrt.jar, scenario.jar, javafxgui.jar, javafx-swing.jar',
width:500, height:500, java_arguments:'-djnlp.packenabled=true'};
var parameters = {"applicationclass":"com.javafxpert.bind_to_function.bindtofunctionapplet",
"draggable":"true"};
var version = '1.6.0' ;
deployjava.runapplet(attributes, parameters, version);
</script>
</html>


notice that the above code enables dragging the applet onto the desktop, as well as using pack200 formatted jar files, if the client machine has java se 6 update 10 installed. give the applet a whirl to see its deployment behavior on your machine.  by the way, according to the java se 6 update 10 plug-in docs , "by default, the gesture to drag the applet out of the web browser is alt + left click + drag."

thanks,
jim weaver
javafxpert.com weblog

Java (programming language) JavaFX

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Pattern Matching for Switch
  • 5 Steps to Strengthen API Security
  • How to Optimize MySQL Queries for Speed and Performance
  • Ultra-Fast Microservices: When Microstream Meets Wildfly

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo