DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. 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 · Interview
Like (0)
Save
Tweet
Share
13.44K 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

  • Introduction to Spring Cloud Kubernetes
  • Orchestration Pattern: Managing Distributed Transactions
  • Implementing PEG in Java
  • A Gentle Introduction to Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: