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. Creating Compiled JavaFX Applets - Method One (of Two)

Creating Compiled JavaFX Applets - Method One (of Two)

James Weaver user avatar by
James Weaver
·
Mar. 09, 08 · Interview
Like (0)
Save
Tweet
Share
16.97K Views

Join the DZone community and get the full member experience.

Join For Free

the javafx script compiler team has provided two ways of creating compiled javafx script applets.  today's example program demonstrates one of these ways, by converting the binding to a function example into a compiled javafx script applet.   here's a screenshot of the javafx script applet, running in firefox 3:

bindtofunctionapplet1

this way of creating a javafx applet is more "java-like" in that it uses the approach of extending the javafx.ui.applet class.  notice that it overrides a couple of applet life-cycle functions to demonstrate that ability.  compare the following code with the binding to a function example, the major difference being the absence of the frame object.  it isn't required since the applet provides its own ui container.

/*
* bindtofunctionapplet1.fx - a compiled javafx program that demonstrates
* one way of creating compiled javafx applets.
* it also demonstrates binding to a function.
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a javafx script example.
*/

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.math;
import java.lang.system;

public class bindtofunctionapplet1 extends applet {
public function start(): void {
system.out.println("bindtofunctionapplet1.start()");
}
public function stop(): void {
system.out.println("bindtofunctionapplet1.stop()");
}
}

class circlemodel {
attribute diameter:number;

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

borderpanel {
var cmodel = circlemodel {}
background: color.white
center:
canvas {
content: [
circle {
cx: 240
cy: 250
radius: bind cmodel.diameter * 2
stroke: color.purple
strokewidth: 1
fill: color.cyan
},
text {
font:
font {
face: fontface.sansserif
style: fontstyle.bold
size: 24
}
x: 20
y: 10
stroke: color.red
fill: color.red
content: bind "diameter: {cmodel.diameter}"
},
text {
font:
font {
face: fontface.sansserif
style: fontstyle.bold
size: 24
}
x: 240
y: 10
stroke: color.red
fill: color.red
content: bind "area: {%3.2f cmodel.getarea()}"
}
]
}
bottom:
slider {
min: 0
max: 100
border:
titledborder {
title: "diameter:"
}
value: bind cmodel.diameter with inverse
minortickspacing: 5
majortickspacing: 10
paintticks: true
paintlabels: true
labels: [
sliderlabel {
value: 0
label:
simplelabel {
text: "0"
}
},
sliderlabel {
value: 50
label:
simplelabel {
text: "50"
}
},
sliderlabel {
value: 100
label:
simplelabel {
text: "100"
}
}
]
}
}

supplying an html file to run the applet

here is the html file (that i've named bindtofunctionappletpage1.html) that runs the applet:

<html>
<body>
<applet code="bindtofunctionapplet1" width=480 height=560
archive="javafxrt.jar, scenario.jar">
</applet>
</body>
</html>

you'll need to put the jar files (shown in the archive tag above) in the same directory as the html file. you can get these files from the compiler download in the dist/lib directory.  to compile this applet, i used the -target parameter so that it will run within browsers that have jre 5 or later:

javafxc -target 1.5 bindtofunctionapplet1.fx

to execute this compiled javafx script applet, either open the bindtofunctionappletpage1.html file in a browser, or use appletviewer as shown below:

appletviewer bindtofunctionappletpage1.html

enjoy, and please post a comment if you have any questions!  the next post will cover the other way of creating compiled javafx script applets.

regards,
jim weaver
javafx script: dynamic java scripting for rich internet/client-side applications

immediate ebook (pdf) download available at the book's apress site

JavaFX JavaFX Script

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Data Stream Using Apache Kafka and Camel Application
  • Decode User Requirements to Design Well-Architected Applications
  • What “The Rings of Power” Taught Me About a Career in Tech
  • Unlock the Full Potential of Git

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: