Java AWT Native Interface: Difference between revisions

Content deleted Content added
OR - copying DLL and other things are OR/not recommended/fact
ce
 
(34 intermediate revisions by 31 users not shown)
Line 1:
{{Multiple issues|
{{multiple|tone=June 2012|unreferenced=June 2012|original research=June 2012}}
{{howtounreferenced|date=June 2012}}
'''Java AWT Native Interface''' is an interface for the [[Java (programming language)|Java programming language]] that enables [[Rendering (computer graphics)|rendering]] [[library (computer science)|libraries]] compiled to [[native code]] to draw directly to a Java [[Abstract Window Toolkit]] (AWT) {{Javadoc:SE|java/awt|Canvas}} [[object (computer science)|object]] drawing surface.
{{original research|date=June 2012}}
{{tone|date=June 2012}}
}}
 
'''Java AWT Native Interface''' ('''JAWT''') is an interface for the [[Java (programming language)|Java programming language]] that enables [[Rendering (computer graphics)|rendering]] [[library (computer science)|libraries]] compiled to [[native code]] to draw directly to a Java [[Abstract Window Toolkit]] (AWT) {{Javadoc:SE|java/awt|Canvas|module=java.desktop}} [[object (computer science)|object]] drawing surface.
The [[Java Native Interface]] (JNI) enabled developers to add platform-dependent functionality to Java [[application software|applications]]. The JNI enables developers to add time-critical operations like mathematical calculations and [[3D rendering]]. Previously, native 3D rendering was a problem because the native code didn't have access to the graphic context. The AWT Native Interface is designed to give developers access to an AWT <code>Canvas</code> for direct drawing by native code. In fact, the [[Java 3D]] API extension to the standard [[Java SE]] [[JDK]] relies heavily on the AWT Native Interface to render 3D objects in Java. The AWT Native Interface is very similar to the JNI, and, the steps are, in fact, the same as those of the JNI. See the [[Java Native Interface]] article for an explanation of the JNI techniques employed by the AWT Native Interface.
 
The [[Java Native Interface]] (JNI) allows developers to add platform-dependent functionality to [[Java (programming language)|Java]] [[application software|applications]]. The JNI enables developers to add time-critical operations like [[Mathematics|mathematical]] calculations and [[3D rendering]].
The AWT Native Interface was added to the [[Java platform]] with the [[Java Platform, Standard Edition|J2SE]] 1.3 ("Kestrel") version.
 
The [[Java Native Interface]] (JNI) enabled developers to add platform-dependent functionality to Java [[application software|applications]]. The JNI enables developers to add time-critical operations like mathematical calculations and [[3D rendering]]. Previously, native 3D rendering was a problemchallenging because the native code didn'tdid not have access to the graphic context. The AWT Native Interface is designed to give developers access to an AWT <code>Canvas</code> for direct drawing bywith native code. In fact, the [[Java 3D]] API extension to the standard [[Java SE]] [[JDK]] relies heavily on the AWT Native Interface to render 3D objects in Java. The AWT Native Interface is very similar to the JNI, and, the steps are, in fact, the same as those of the JNI. See the [[Java Native Interface]] article for an explanation of the JNI techniques employed by the AWT Native Interface.
== AWT Native Interface steps ==
{{howto|date=June 2012}}
A complete walkthrough example of this technology is available on Wikibooks (see link below).
 
The AWT Native Interface is very similar to the JNI, and the steps are the same as those of the JNI. See the [[Java Native Interface]] article for an explanation of the JNI techniques employed by the AWT Native Interface. The AWT Native Interface was added to the [[Java platform]] with the [[Java Platform, Standard Edition|J2SE]] 1.3 ("Kestrel") version.
=== Create a Java application ===
See the [[Java Native Interface]] article for an explanation of the <code>native</code> [[keyword (computer programming)|keyword]] and the <code>loadLibrary()</code> method. A <code>paint()</code> method will be simply invoked when the AWT [[event dispatching thread]] "repaints" the screen.
 
== AWT Native Interface stepspainting ==
=== Create a C++ header file ===
One can paint as if it is a native application. In [[Microsoft Windows|Windows]], the JVM will pass a HWND and other window information to the native application so that the application will "know" where to draw. It could use GDI to draw a Rectangle. The window information the native side needs will be in a <code>JAWT_Win32DrawingSurfaceInfo</code> structure (depending on the [[Operatingoperating Systemsystem]]) which can be retrieved with this line: {{code|lang=c|1=dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;}}
Create the [[C++]] [[header file]] as usual (See [[Java Native Interface]] for more complete explanations.)
 
==References==
=== Implement the C++ native code ===
{{reflist}}
Type this in a file named "NativeSideCanvas.cpp" and compile into a library. See [[Java Native Interface]] for a more complete explanation. (For [[Solaris Operating System|Solaris]] code and other operating systems see links below.)
 
=== Run the program ===
One should run the file as usual. One should then see a window with, for example, a rectangle drawn in it. (See [[Java Native Interface]] for complete instructions.)
 
Note: One can notice that the AWT Native Interface requires the "jawt.dll" (or "jawt.so") to run with the application, so the easiest way to do that is copying the "jawt.dll" (should be in the .../jre/bin [[file path]] of the JDK's installation path.){{fact|date=June 2012}}
 
== Native painting ==
One can paint as if it is a native application. In [[Microsoft Windows|Windows]], the JVM will pass a HWND and other window information to the native application so that the application will "know" where to draw. It could use GDI to draw a Rectangle. The window information the native side needs will be in a <code>JAWT_Win32DrawingSurfaceInfo</code> structure (depending on [[Operating System]]) which can be retrieved with this line: dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
 
== See alsoExternal links==
{{wikibooksPortal|Java_Swings/AWT|graphicComputer programming in Java}}
{{Wikibooks|Java Swings/AWT}}
* [httphttps://docs.oracle.com/javase/78/docs/technotes/guides/awt/AWT_Native_Interface.html The AWT Native Interface]
*[https://www.infoworld.com/article/2077589/java-tip-86--support-native-rendering-in-jdk-1-3.html Support native rendering in JDK 1.3]
 
{{Java desktop}}
== External links ==
* [http://docs.oracle.com/javase/7/docs/technotes/guides/awt/AWT_Native_Interface.html The AWT Native Interface]
 
[[Category:Java platform|AWT Native Interface]]