Applet and JavaFX and Confusion

Two weeks back in BOJUG meeting, I have seen lot many engineers getting confuse with JavaFX. They want to know how to run FX code in browser. Shall we use applet to run FX code. And many more. Though it tough to explain everything in a small presentation but Harish Singh and we have tried our best to explain some of the queries. Yes, FX can be very well run in an applet. I have written one HelloWorld type of example for running FX code inside applet. Its very well same. \*.fx file create a .class file and then handling in the same way as we do with .class file.

Here is a small code for "My Hello World" (HelloApplet.fx)

import javafx.ui.\*;

  content: Label {
    text: "My Hello world!"

Now you have to compile this with javafxc, so that we can use class file. For that you need to download javafx compiler, runtime and some more jars. From this link you can download it.

Now here is little tough part, making html file for applet :-). Tough because you get to know which jar files your code is using. And you will not get documents readily to say you which API belong to which package + API's in themselves are changing. So, you may not able to run your older codes. Anyway, I have written this html code(Hello.html):
    <applet code="javafx.ui.Applet" width=480 height=560
     archive="javafxrt.jar, Scenario.jar, javafxgui.jar, javafxc.jar, javafx-swing.jar, javafx.jar">
     <param name="AppletClass" value="HelloApplet"> 

Don't ask me why I have added some many archive. I got frustrated in knowing what residing where. And so, I have ended up adding all the jar that I have seen in the archive(in the link) :). Check it out, let me know if there exist any problem.

Surprisingly you can call Frame also from applet, check this code:

import javafx.ui.\*;
Frame {
   title: "Hello World F3"
   width: 200
   content: Label {
      text: "Hello World"
   visible: true
In the next blog I will also cover some other way to use on web.


As far as I am concerned, Netbeans plugin should have a simple way of allowing you to create a JavaFX project and then have a right-click command saying "Export to Web" and then BOOM! it generates all the HTML and JavaScript needed to run in browsers. Users should just embed the HTML snippet in thier webpages on BOOM it works. Nobody would need to start knowing all these.

Posted by grace on July 14, 2008 at 07:14 AM IST #

Probably Yes !

Posted by Vaibhav on July 14, 2008 at 07:19 AM IST #

Hi Vaibhav,
I read your blog describing JAVAFX. Though i have some confusion. Please do remove that as only you can do that. Presently i am making my application using the dojo framework, a framework for javascripting API. i have full and strong understanding of JAVA + J2EE and also familier with the applet performance issues.

Generally applets are heavy weight and created problem in accessing teh client machine. Although we have to sign the jar for that by my question is not that.

i want to compare the javascript using on the HTML pages and the javafx. Will it be feasible in context with the performance issue to replace the javascript with the javafx. can we develop the fully integrated application like google calender using JAVA FX. Please do reply as it is necessary

Posted by vaibhav saxena on July 15, 2008 at 11:37 AM IST #

Yes we can. Only thing in which we are lagging is still not many users(like me) start using it. You can see some of the fully loaded application in JavaFX in NetBeans example. Some complete site got developed in JavaFX. It will take sometime to get acquainted with the API. Performance I can't compare with JavaScript !
But JavaFX engineers are continuously working on it and will give some fruitful result soon.

One line of your comment:
Please do remove that as only you can do that.

What only I can do that. I didn't got the point ?

Posted by Vaibhav on July 15, 2008 at 11:50 AM IST #

Hi vaibhav,
well vaibhav can give me some site example which are using JAVAFX inspite of javascript. i am too much egar to implement my app in JAVAFX and there by as you have wrote such a nice article I come to the point that you have good hands onto the JAVAFX. the comment that as only you can do means that you can made me understand the better use of JAVAFX.

Thanks again

Vaibhav Saxena

Posted by vaibhav saxena on July 16, 2008 at 04:50 AM IST #

there are some undergoing. Frankly its not very stable now, it will take some more time. has some javafx work in site dev. i guess.

You are welcome. I will keep on posting the new thing if it happen :)

Posted by Vaibhav on July 17, 2008 at 05:49 PM IST #

Hi vaibhav,
Thanks for your blog,I learn a lot from it.But, when I compiled the javafx script file on my computer, there is a question: can not find the javafx.ui package.
I already use set the classpath include all jars it may need, it still has the problem. Can you give me some advice?
Thank You!

Posted by ZhangCheng on July 27, 2008 at 11:53 PM IST #

Thanks Zhang. This problem you can face, if you have downloaded the new FX package. In the new FX package things are complete get changed. If you read my current 2nd and 3rd post, you can see that. But if you are using older jar files, then it should run, trying putting all the jar files locally with code.

But now its good to go on the builder of FX which Netbeans 6.1 is providing(3rd post from the top). Please let me know if you still find problem.

Posted by Vaibhav Choudhary on July 28, 2008 at 04:04 AM IST #

Thanks for your reply.
Yes, now, I use NetBeans 6.1 to practice JavaFX,It is very cool and convenient!
Thank you again. I learn a lot from you blog. I hope you would write more blogs about JavaFX, some example such as the style of the
It is too cool.
Thank you!

Posted by ZhangCheng on July 28, 2008 at 05:26 AM IST #

ya it will take some effort to make animation like on site :)
But API's is growing and more help will be available on internet, it will be easy

Posted by Vaibhav Choudhary on July 29, 2008 at 06:24 AM IST #

Export as an applet is simple it seems.The dist folder has the related html for runningthe application as applet , jnlp related stuffs.


Posted by sezhian on May 21, 2009 at 05:13 AM IST #

Hi Vibhav,
Would like to know about the performance of javaFX as it uses applets.
If 400 concurrent users access the javaFX web application over the internet or intranet what could be the performance in terms of response and stability. Thanks in advance.

Posted by Alak on June 30, 2009 at 04:40 AM IST #

Dude you need to brush up your English.

Posted by guest on July 06, 2010 at 11:48 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

Vaibhav Hi, I am Vaibhav Choudhary working in Oracle with JDK team. This blog is all about simple concept of Java, JVM and JavaFX.


« August 2016