简体   繁体   中英

Where can I find detailed information on how AWT interacts with the native OS?

I've been searching for detailed information regarding the fundamentals of the AWT package. Specifically how it interacts natively with the host OS to create Windows and their contents.

Can anyone point me to this kind of documentation or provide any other information?

OpenJDK source is the way to go. You just need to hit the correct folder. You can see inside code like this:

checkbox = new AwtCheckbox();
...
checkbox->CreateHWnd(env, labelStr, style, exStyle,
         x, y, width, height,
         awtParent->GetHWnd(),
         reinterpret_cast<HMENU>(static_cast<INT_PTR>(
     awtParent->CreateControlID())),
         ::GetSysColor(COLOR_WINDOWTEXT),
         ::GetSysColor(COLOR_BTNFACE),
         peer);

CreateHWnd function can be found in awt_Component.cpp file, where it calls CreateWindowEx function.

Basic:
Most GUI class libraries in C++ are platform specific, not just because of different hardware capabilities, but subtle differences between the "look-and-feel" of various Windowing operating systems. The Java Abstract Window Toolkit provides a cross-platform library which seeks to observe look-and-feel conventions of various OS platforms.

            Toolkit ------------------------------------------------ AWT
       --------|---------
   Button               List                                         JVM
  ------|-------------|--------------------------------------------------
  Button Peer     List Peer                       Native GUI (Windows, Mac, X) 

More information about Java GUI Event Programming

AWT provides two levels of APIs:

  • A general interface between Java and the native system, used for windowing, events, and layout managers. This API is at the core of Java GUI programming and is also used by Swing and Java 2D. It contains:

    1. The interface between the native windowing system and the Java application;
    2. The core of the GUI event subsystem;
    3. Several layout managers;
    4. The interface to input devices such as mouse and keyboard;
      and
    5. A java.awt.datatransfer package for use with the Clipboard and Drag and Drop.
  • A basic set of GUI widgets such as buttons, text boxes, and menus.
    It also provides the AWT Native Interface , which enables rendering libraries compiled to native code to draw directly to an AWT Canvas object drawing surface.

AWT also makes some higher level functionality available to applications, such as:
Access to the system tray on supporting systems; and The ability to launch some desktop applications such as web browsers and email clients from a Java application.
To get the Source code for the Native OpenJDK AWT classes use below link

jdk6/jdk6-gate/jdk/src/windows/native/sun/
jdk6/jdk6-gate/jdk/src/windows/native/sun/windows/ (Windows-AWT-Native classes).

OpenJDK (GPL)

  • Sun announced in 2006 that Java would become open-source software.
  • Released the complete source code of the Java Class Library under the GPL on May 8, 2007,
  • On October 11, 2010, IBM, by far the biggest participant in the Apache Harmony project, decided to join Oracle on the OpenJDK project, effectively shifting its efforts from Harmony to OpenJDK.
  • On January 11, 2011, the Mac OS X Port Project was created on OpenJDK, and Apple made the first public contribution of code to the project. The initial Apple contribution built on the OpenJDK BSD port( OpenJDK™ 6 Source Release ).

Reference:

[ OpenJDK Repositories .]

Open jdk6/jdk6-gate/jdk/src/share/classes/java/awt/ (Example AWT Package Source code)

The main OpenJDK project , which is based on JDK 7

You can find out OpenJDK features here

Caciocavallo , Project that provides an OpenJDK-based Java API to ease AWT implementation on new systems.The project has successfully implemented AWT widgets using Java2D.
[OpenJDK Mailing list .]

Read AWT Documentation to get Clear knowledge on it's implementations.

Fallow awt-dev Mailing Lists to get involved.

It is an implementation detail. The defacto standard would be how Oracle has implemented it. If you really really want to know then take a look at the source code. It can be found at http://openjdk.java.net/ . The links are in the left column below the search box. The relevant classes should be in the sun.awt package.

Well there is pdf (mentioned below).... but for me it is quite hard to understand. But it may be helpful to you.

How Java Programs Interact with Virtual Machines at the Microarchitectural Level.

Awt does this using native methods. These are java methods that reference methods in the native language in a separate file. So essentially if you are using windows and you want to open a window, java will use C++ to open the window.

http://en.wikipedia.org/wiki/Java_Native_Interface

http://en.wikipedia.org/wiki/Java_AWT_Native_Interface

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM