Content deleted Content added
Josh Parris (talk | contribs) m Robot-assisted disambiguation: Render - Changed link(s) to Rendering (computer graphics) |
transferred how-to on Wikibooks |
||
Line 1:
'''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.
Line 6 ⟶ 5:
The AWT Native Interface was added to the [[Java platform]] with the [[Java Platform, Standard Edition|J2SE]] 1.3 ("Kestrel") version.
== AWT Native Interface
A complete walkthrough example of this technology is available on Wikibooks (see link below).
=== 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.
=== Create
Create the [[C++]] [[header file]] as usual (See [[Java Native Interface]] for more complete explanations.)
=== Implement the C++ native code ===
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.)
== 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 also ==
Line 169 ⟶ 34:
* [[Abstract Window Toolkit]]
* [[Event dispatching thread]]
* [[:wikibooks:Java_Swings/AWT|Java Swings, a Wikibook about graphic programming in Java]]
== External links ==
|