Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Java Tip 86: Support native rendering in JDK 1.3

Gain portability and a quicker development cycle, without sacrificing performance of native GUI code

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 2 of 2

Java_MyWindow_paint is the entry point that the JVM will invoke for drawing the MyWindow. The helper function DrawSmiley does the actual rendering using Win32 calls. To include GetDrawingSurfaceInfo in your application, use the jawt.lib external library (see "Build the environment").

Step 4: Edit BUILD.BAT

Edit BUILD.BAT before running it and set the path for your Visual C++ 6.0 and JDK 1.3 directories as shown below. The BUILD.BAT compiles MyWindow.java, generates MyWindow.h, and then compiles MyWindow.CPP into MyWindow.DLL.

SET DEVSTUDIO=D:\Program Files\Microsoft Visual Studio\VC98
SET JDK13=D:\JDK1.3


That's it; you are ready to go. Before running the sample, make sure that MyWindow.DLL, \JDK1.3\BIN, and \JDK1.3\JRE\BIN are in your PATH, and that the current directory is in CLASSPATH; this will guarantee that MyWindow.class will load successfully. After making sure that the PATH and CLASSPATH are set properly, enter java MyWindow on the command line to run the application. A RUN.BAT batch file is included in window.zip (see Resources) for your convenience. Edit RUN.BAT to set the PATH and CLASSPATH for JDK 1.3.

Build the environment



  • Headers: New C headers for the Windows platform have been added to the JDK's include directory. They are:


    include/jawt.h.
    include/win32/jawt_md.h.


    According to the JavaSoft Website, these headers are not part of the Java 2 Platform's official specification; rather, they are provided as a convenience to developers who want a standardized way to access native drawing functionality. I think this means that people who port the JDK to other platforms can choose not to expose this API.

    About the author

    Davanum Srinivas is currently a developer at Computer Associates.
  • Libraries: A new library, named jawt.lib, has been added to the SDK's library directory. As explained earlier, it has the entry points needed for including J2AWT in your application. For example, to link to the GetDrawingSurfaceInfo entry point, you need to include jawt.lib in your build.
  • Tools: The javah tool is used to generate the C/C++ header file for the native functions of the Java class, and the javac tool is used to compile the Java source.



Conclusion

Migrating a legacy software system to Java is a nontrivial task, especially if it includes a high-performance rendering engine. The Java 2 AWT Native Interface makes it easier to migrate in stages, allowing code that is not performance sensitive to be migrated before the critical rendering code. It also makes third-party widget developers more likely to take a serious look at developing products for Java. With the Java 2 AWT Native API, you can port existing legacy GUI code and finish development more quickly, without sacrificing your investment in the performance of a key piece of native code.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources