Monday Dec 01, 2008

One scene to other - JavaFX

Any middle or big application demands to change one window to other at some point of time. A window type of thing in JavaFX is represented by Scene and its each to switch between scene or to run multiple scenes.

Here is a small application in which clicking on image will put you in another window, written "Hello World" 

package sample6;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;

var s_new:Scene;
var s = Scene {
   content: [
       Text {
           font: Font {
               size: 24
           }
           x: 10,
           y: 30
           content: "HelloWorld"
       }
   ]
};

var s1 = Scene {
   content: [
       ImageView {
           image: Image {
               url: "{__DIR__}im2.PNG"
           }
           onMouseClicked: function( e: MouseEvent ):Void {
               s_new = s;
           }
       }
   ]
};

s_new = s1;
Stage {
   title: "Application title"
   width: 250
   height: 280
   scene: bind s_new
} 

So, its simple, on mouse click, I have bind a scene variable with a new scene. That's it !


Thursday Mar 13, 2008

How many JRE on my Windows machine

Today we are doing some discussion on JRE and one of my friends Lawrence asked me a question "How to find how many JRE are installed on system by Java Code ? " Now I don't think Java have any such API which will tell how many JRE are installed on System and what are they ? But my another friend Vikram has a saying that JRE installation write information in Registry. And here I tried to write this code. It will only run on Windows :) because again I have used Runtime class. I would love to know how the same could be achieved in Unix Systems. This code is not doing anything, just do query from registry and reflectes the answer on the console. 

import java.io.\*;
class NoofJRE {
static String REG_PATH = "reg query " +
    "\\"HKLM\\\\Software\\\\JavaSoft\\\\Java Runtime Environment";
 
  public static void  getJREInfo() {
    try {
    Process process = Runtime.getRuntime().exec(REG_PATH);
      InputStream inputstream = process.getInputStream();
      InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
      BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
      String line;
      while ((line = bufferedreader.readLine()) != null) {
           System.out.println(line);
      }
  }
    catch (Exception e) {
      System.out.println("I am in Exception");
    }
  }
  public static void main(String s[]) {
    getJREInfo();
    }
}

And here is my output:

E:\\Program Files\\Java\\jdk1.6.0\\bin>java NoofJRE
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment
    CurrentVersion      REG_SZ  1.6
    BrowserJavaVersion  REG_SZ  1.6.0_01
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.4.2_17
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0
HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.6.0_01

Which sounds true in my case. It is clearly telling me that I have JRE 1.4.2_17, 1.6.0 and 1.6.0_01. I have old bad habit on not uninstalling JRE's :). Please let me know if there is any other way to know how many and which JRE is/are installed in my system.

And to know where it is installed is also easy by querying  JAVA_HOME in registry value.



 

Friday Dec 07, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part IV

So its all done for Windows. Now coming on to Solaris, here the work is little less in compare to Windows(the same is valid for Linux as well, can be a excuse for me as I don't have Linux machine right now). Here is the list of downloads:

-> OpenJDK - Same link as mentioned in the previous blog (download the Solaris part, we have worked on Solaris x86)
-> Binary Plugin - Download from here.
-> CUPS Header - Download the latest cups from here.
NOTE: CUPS is Common Unix Printing System. It is doing a smart job of putting browser information into a printable format. I mean you don't have to worry about how printing is going to happen, it will be taken care by CUPS.
-> FreeType - Download from the same link provided in the previous blog. Any of the platform independent version will work for us.
-> jtreg - jtreg can be downloaded from the same link from where you are downloading OpenJDK. jtreg is a test suite that contains tons of testcase. Responsibility is to write a safe code and code change will not screw anything.

Thats it ! I am assuming that you have Netbeans 6+ and JDK 1.7 and JDK 1.6 binaries installed with you.

Now setting the build.properties file. Its very small in comparison to windows. Here it is:

bootstrap.jdk={PATH_JDK7_INSTALL}
jtreg.home={JTREG_PATH}
make.options=\\
// this is important because code contains many
//line which work on if(OPENJDK==true) code
OPENJDK=true \\
ALT_BINARY_PLUGS_PATH={PATH_BINARY_PLUGS} \\
ALT_JDK_IMPORT_PATH={PATH_JDK7_INSTALL} \\
ALT_FREETYPE_LIB_PATH={FREE_TYPE_PATH}/lib \\
ALT_FREETYPE_HEADERS_PATH={FREE_TYPE_PATH}/include \\
ALT_BOOTDIR={PATH_JDK6_INSTALL} \\


All done. Time to fire the build. More likely you will face the same problem what we have mentioned for Windows. If you are lucky enough then you will get the message "BUILD SUCCESSFUL"
(If I missed some step, please follow as it is in previous blog)

Sunday Dec 02, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part III

Now if you all set according to the last blog. This is/are the possible error(s) :

1. Error in make file : Multiple target \*\*\* . Yes, you need to downgrade the version of make file. "make.exe" resides in /cygwin/bin/make.exe. Check out its version, if its not 3.80, time to downgrade it. Download from here. Replace the make.exe of cygwin with this new make.exe ( make -version should be 3.80).
NOTE: make.exe is responsible to run make files. Makefiles are the one which contains instructions for a specific project, which file to compile and in which order.

2. Compilation error in LocaleDataMetaInfo.java - Try out Igor's solution
NOTE: Cygwin(make of Cygwin) still have some problem in understanding \\r character. So, this error may go with the upcoming binaries of Cygwin. One way is just remove \\r from the sh file - localegen.sh. But then you will not get the proper LocaleDataMetaInfo.java file.

3. freetype.dll not found: Yes, freetype installation is  not creating any file like freetype.dll and this is surprising. If you investigate properly, you will get one file with name freetype.dll.a. Right now, lets rename it to freetype.dll(later we will check the problem of renaming this file)
NOTE: Just one line about freetype, it is providing uniform interface to access font files, support anti-aliasing as well.

4. I guess this is the main three error we came across. If anything else coming, then you need to check the installation of Cygwin again.  Errors like zip or tar.exe not found, means you have not installed the archive package of Cygwin.

Now if you are lucky enough, all things go fine and build will be ready. Again note that, jdk project module of Netbeans is only responsible for j2se build which mostly contains Java API not containing hotspot part. So, check the javac.exe and java.exe of your own openJDK build in the folder /openjdk/windows-i586/bin/.

5. Give a try to your HelloWorld.java Program. Ah it is running :-) cool. Now give a try on SimpleFrame.java in which you are creating a Frame. If unluck you will get this error: not a proper dll file: freetype.dll. So, renaming is not actually working which we did in Error 2. Actually .a is a library achieve which is not a proper  file at this point. So, what to do ? Either find proper freetype.dll file from somewhere or take the source of freetype and compile it on .NET according to these rule.

Now its all yours. If you get any additional error, please let me know via comment or drop me a mail

 

Saturday Dec 01, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part II

Talking of some of the details about OpenJDK building(on Netbeans), we can start with Windows build(x86). In general,building on windows is tougher than Solaris/Linux because there are lot of dependencies on other tools and we can't set up the tools on network. Now lets see the list of the downloads required (don't abuse me, I know its too much :-))

- OpenJDK - Download open source JDK

- Binary Plugin - Download Binary Plugin 

We need to install binary of Java SE 6, which we can get from Sun site and Java SE 7 which we can download from http://download.java.net/jdk7/binaries

Now this is all about JDK downloads. Time to put hand into the dirty world of other dependent tools:

1. As we have lot of C++ code(native code) inside JDK, we need a C++ compiler. For windows, JDK document suggests to use .NET2003. Though we have made the build on .NET 2003 but I guess compiler of .NET 2003 is free on net and you can give one try with free compiler. Note here: Don't try with .NET 2005 as many of the API get deprecated.

2. Cygwin Installation: This is a area of concern. We have invested(wasted :D) 90 percent of the build time in this tool. Installing, uninstalling, reinstalling .. and  it keep on going. On the first installation page of Cygwin itself , you will get two options: Unix/Binary or Dos/Text. Any option can work, can't work depending on your luck :-). Most of the engineer suggested me to install Unix/Binary but Dos/Text worked for us :D. Download from: Cygwin Site

NOTE: Don't forget to download Developer, System, Utility, Archive  package of its full mode not the default mode.

3. Install Microsoft DirectX 9.0 SDK(Summer Package) - Download it from Microsoft site

4. Download and Install FindBugs and Ant

5. Download Microsoft Unicode Library

6. Download and install latest version of freetype from www.freetype.org

7. Oops, if you don't have Netbeans 6 then download that also :)

Time to take a cup of coffee. Let the download to go on.

OK, back from coffee ...

Add Ant, Findbugs, Cygwin(till \\bin) in the path variable of system.  Open cmd, run vsvars32.bat (Micros~1.NET\\Common7\\Tools\\vsvars32.bat) to initialize the .NET variables. Run Netbeans.exe from the same command line.

Open openjdk/jdk/make/netbeans/ in netbeans and open project jdk. Open some of the important file like build.propertied and make.xml. In make.xml file, you will get the path of make, change it to the cygwin make file {cygwin/bin }.

Now IMPORTANT, get ready to write build.properties file:

bootstrap.jdk={PATH_JDK7_INSTALL}
make.options=\\
// this is important because code contains many
//line which work on if(OPENJDK==true) code
OPENJDK=true
// write the path in ~ format (dir /x)
ALT_COMPILER_PATH={MS.NET2003_PATH}/Vc7/bin \\    
ALT_MSDEVTOOLS_PATH= {MS.NET2003_PATH}/Common7/Tools/Bin \\
ALT_MSVCR71_DLL_PATH= {MS.NET2003_PATH}/SDK/v1.1/Bin \\
ALT_BOOTDIR={PATH_JDK6_INSTALL} \\
ALT_BINARY_PLUGS_PATH={PATH_BINARY_PLUGS}
ALT_JDK_IMPORT_PATH={PATH_JDK7_INSTALL} \\
ALT_DXSDK_PATH={DIRECTX_PATH} \\
ALT_FREETYPE_LIB_PATH={FREE_TYPE_PATH}/lib \\
ALT_FREETYPE_HEADERS_PATH={FREE_TYPE_PATH}/include \\
ALT_UNICOWS_LIB_PATH={UNICOWS_PATH} \\      
ALT_UNICOWS_DLL_PATH={UNICOWS_PATH} \\
LD_LIBRARY_PATH= \\
CLASSPATH= \\
JAVA_HOME= \\
SHLVL=1 \\     
             

All Done ! Fire the build now, if you are lucky enough you will get it done in some 20-30 minutes. In the next blog, we are going to talk about the problem(s) with some of this software and version dependencies.

Friday Nov 30, 2007

OpenJDK Build on Netbeans with Windows / Solaris - Part I

Our team is ready with OpenJDK build for FOSS.IN, better to
say partially ready :). Me and Vikram is going to give the live demo about
building OpenJDK and how you can optimize the source code according to your own
need. For Example, if you don't like the default LookAndFeel of Java, change it according to
your like because now its your world, its your Java. Let me show you one simple
code change we have done with the gradient color. This
is the normal Ocean LookAndFeel of Java.

Before the code Change:

 

 After the code change:

 

 

Though building OpenJDK is little cumbersome process but come on, its a one time process. Just make the build ready once and then screw it as you want both on the Java level and on native level . Even more process and standard documents will come as OpenJDK goes into its maturity stage. You will love to know that Netbeans 5.5+ is giving a high class support for making OpenJDK across all platforms.


So for the real die-hard of Java, I am going to write Part II, III, ... upto N(covering some technicalities of building process) till I am not able to make you happy. Thanks to Igor and Sandeep who have replied my all shots of stupid questions.

 

About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today