On
JavaDay in St. Petersburg, I was asked the question: “Is JavaFX suitable for writing
browsers - small browser games?” My answer: “Yes, of course it is suitable,” obviously needs confirmation. This publication is devoted to this.
In JavaFX 2.1, there is a rich opportunity for such applications in the field of graphics, animation, and media content support. To use them, you do not need to learn a new programming language, just enough knowledge of Java.
The API is relatively small. To understand the basic concepts will help slides from my
presentation . For everything else, there is the Java community and many libraries available for the Java language.
Next, we will discuss the application deployment and adding it to the social network VKontakte.
The deployment models of JavaFX applications include, in addition to the usual desktop, two more web options:
- jnlp-file is in case when the application does not make sense to work within the browser,
- and applet - the same option when the application runs directly on the page in the browser
The
VKontakte network allows you to easily use applets as attachments. We will take advantage of this.
')
Take, for example, the application
BrickBreaker , which, together with the source code, can be downloaded from the official site
oracle.com/javafx . Opening the project in
NetBeans and compiling it, we see the following:

The contents of the
dist folder:
- BrickBreaker.jar - file with compiled application classes
- BrickBreaker.jnlp - jnlp file
- BrickBreaker.html - preparing a web page with a built-in JavaFX applet
- the web-files folder contains the files necessary for displaying the html-page and, in particular, the dtjava.js javascript file that loads the JavaFX applet on the page
To add an application to the contact, we will need to place all these files (with the exception of jnlp) on some
hosting , for example, on the website
Narod.ru . After uploading files to the server, it makes sense to check that the
BrickBreaker.html page is available and launch our application directly in the browser.
Next, go to the contact page
Developers and click
Create an application . Enter the name and select the type of
IFrame / Flash application .

After entering the confirmation code, go to the
Settings tab, select the type of application
IFrame and specify the
address IFrame - link to BrickBreaker.html from your site. Save the changes.

The application is almost ready. As practice shows, it will already work in Google Chrome 18, and in Internet Explorer 8. However, the more cautious Firefox 12 will block it. The reason is that an error crept into the dtjava.js file:
top.execScript is accessed , which is generally forbidden for cross-domain nested frames. To remedy this situation, you must replace all occurrences of the string “top.execScript” with “window.execScript” in the
web-files / dtjava.js on your server.

The rest is trifles: remove extra text from the html file and adjust the size of the applet. Now your JavaFX application works in contact:

Using JavaFX 2.1, it is easy to create applications for the social network VKontakte. In the next post I will show how you can interact with the VKontakte API to get information about the user and other operations.