Java AWT Native Interface (jawt) is an interface for the
Java programming language
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run an ...
that enables
rendering
Render, rendered, or rendering may refer to:
Computing
* Rendering (computer graphics), generating an image from a model by means of computer programs
* Architectural rendering, creating two-dimensional images or animations showing the attributes ...
libraries
A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
compiled to
native code
In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a ver ...
to draw directly to a Java
Abstract Window Toolkit
The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-interface widget toolkit, preceding Swing. The AWT is part of the Java Foundation Classes (JFC) — the standard API for providing a graphica ...
(AWT)
object
Object may refer to:
General meanings
* Object (philosophy), a thing, being, or concept
** Object (abstract), an object which does not exist at any particular time or place
** Physical object, an identifiable collection of matter
* Goal, an ai ...
drawing surface.
The
Java Native Interface
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
(JNI) allows developers to add platform-dependent functionality to Java
applications
Application may refer to:
Mathematics and computing
* Application software, computer software designed to help the user to perform specific tasks
** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
. The JNI enables developers to add time-critical operations like mathematical calculations and
3D rendering
3D rendering is the 3D computer graphics process of converting 3D models into 2D images on a computer. 3D renders may include photorealistic effects or non-photorealistic styles.
Rendering methods
Rendering is the final process of creati ...
. Previously, native 3D rendering was technically challenging 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
Canvas
for direct drawing with native code. In fact, the
Java 3D
Java 3D is a scene graph-based 3D application programming interface (API) for the Java platform. It runs on top of either OpenGL or Direct3D until version 1.6.0, which runs on top of Java OpenGL (JOGL). Since version 1.2, Java 3D has bee ...
API extension to the standard
Java SE
Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).
The platform uses J ...
JDK
The Java Development Kit (JDK) is a distribution of Java Technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java ...
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
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
article for an explanation of the JNI techniques employed by the AWT Native Interface. The AWT Native Interface was added to the
Java platform
Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cro ...
with the
J2SE
Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).
The platform uses Jav ...
1.3 ("Kestrel") version.
AWT Native Interface steps
A complete walkthrough example of this technology is available on Wikibooks (see link below).
Create a Java application
See the
Java Native Interface
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
article for an explanation of the
native
keyword
Keyword may refer to:
Computing
* Keyword (Internet search), a word or phrase typically used by bloggers or online content creator to rank a web page on a particular topic
* Index term, a term used as a keyword to documents in an information syste ...
and the
loadLibrary()
method. A
paint()
method will be simply invoked when the AWT
event dispatching thread The event dispatching thread (EDT) is a background thread used in Java to process events from the Abstract Window Toolkit (AWT) graphical user interface event queue. It is an example of the generic concept of event-driven programming, that is popula ...
"repaints" the screen.
Create a C++ header file
Create the
C++ header file
Many programming languages and other computer files have a directive, often called include (sometimes copy or import), that causes the contents of the specified file to be inserted into the original file. These included files are called copybooks ...
as usual. (See
Java Native Interface
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
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
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
(JNI) for a more complete explanation. (For
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
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by
native applications (programs specific to a hardwa ...
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
A path is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The del ...
of the JDK's installation path.)
Native painting
One can paint as if it is a native application. In
Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ...
, 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
JAWT_Win32DrawingSurfaceInfo
structure (depending on
Operating System
An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
) which can be retrieved with this line:
External links
The AWT Native Interface
{{Java desktop
AWT Native Interface