Hoppa till innehållet

Abstract Window Toolkit

Från Wikipedia
Version från den 15 december 2012 kl. 18.00 av Hubba (Diskussion | Bidrag) (från enwp)
(skillnad) ← Äldre version | visa nuvarande version (skillnad) | Nyare version → (skillnad)

Mall:Use dmy dates

Windows form with some AWT examples

The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes (JFC) — the standard API for providing a graphical user interface (GUI) for a Java program.

AWT is also the GUI toolkit for a number of Java ME profiles. For example, Connected Device Configuration profiles require Java runtimes on mobile telephones to support AWT.

History

When Sun Microsystems first released Java in 1995, AWT widgets provided a thin level of abstraction over the underlying native user-interface. For example, creating an AWT check box would cause AWT directly to call the underlying native subroutine that created a check box. However, a check box on Microsoft Windows is not exactly the same as a check box on Mac OS or on the various types of Unix. Some application developers prefer this model because it provides a high degree of fidelity to the underlying native windowing toolkit and seamless integration with native applications. In other words, a GUI program written using AWT looks like a native Microsoft Windows application when run on Windows, but the same program looks like a native Apple Macintosh application when run on a Mac, etc. However, some application developers dislike this model because they prefer their applications to look exactly the same on every platform.

In J2SE 1.2, the Swing toolkit largely superseded the AWT's widgets. In addition to providing a richer set of UI widgets, Swing draws its own widgets (by using Java 2D to call into low-level subroutines in the local graphics subsystem) instead of relying on the operating system's high-level user interface module. Swing provides the option of using either a system "look and feel" which uses the native platform's look and feel, or a cross-platform look and feel (the "Java Look and Feel") that looks the same on all windowing-system.

Abstract Window Toolkit (AWT) is a set of application program interfaces ( API s) used by Java programmers to create graphical user interface ( GUI ) objects, such as buttons, scroll bars, and windows. AWT is part of the Java Foundation Classes ( JFC ) from Sun Microsystems, the company that originated Java. The JFC are a comprehensive set of GUI class libraries that make it easier to develop the user interface part of an application program.

Architecture

The AWT provides two levels of APIs:

AWT also makes some higher level functionality available to applications, such as:

Neither AWT nor Swing are inherently thread safe. Therefore, code that updates the GUI or processes events should execute on the Event dispatching thread. Failure to do so may result in a deadlock or race condition. To address this problem, a utility class called SwingWorker allows applications to perform time-consuming tasks following user-interaction events in the event dispatching thread.

Mixing AWT and Swing components

Prior to Java 6 Update 12, mixing Swing components and basic AWT widgets often resulted in undesired side effects, with AWT widgets appearing on top of the Swing widgets regardless of their defined z-order. This problem was because the rendering architecture of the two widget toolkits was very different, despite Swing borrowing heavyweight top containers from AWT.[1]

Starting in Java 6 Update 12, it is possible to mix Swing and AWT widgets without having z-order problems.[2][3]

Implementation

As the AWT is a bridge to the underlying native user-interface, its implementation on a new operating system may involve a lot of work, especially if it involves any of the AWT GUI widgets, because each of them requires that its native peers be developed from scratch.

A new project, Caciocavallo, has been created, that provides an OpenJDK-based Java API to ease AWT implementation on new systems.[4][5] The project has successfully implemented AWT widgets using Java2D.[6] All the necessary core-JDK modifications have since been pushed to OpenJDK 7,[7] which means that Java can now be used on a graphics stack other than one of those provided by the official JDK (X Window System, OpenGL or DirectX), by including an external library and setting some system properties. A DirectFB backend for Caciocavallo[8] is under development, as is an HTML5 backend; the aim is to deploy existing Swing applications—without Java support—as ordinary web applications running on a web server.[8][9]

See also

graphic programming in Java på Wikibooks.

References

Mall:FOLDOC

  1. ^ Fowler, Amy (1994). ”Mixing heavy and light components”. Mixing heavy and light components. Sun Microsystems. http://java.sun.com/products/jfc/tsc/articles/mixing/index.html. Läst 17 december 2008. 
  2. ^ Geertjan, Wielenga (16 December 2008). ”A Farewell to Heavyweight/Lightweight Conflicts”. A Farewell to Heavyweight/Lightweight Conflicts. http://java_dzone_com/news/a-farewell-heavyweightlightwei. Läst 17 december 2008. 
  3. ^ ”Bug/RFE fixed in current JDK 6u12 build”. Bug/RFE fixed in current JDK 6u12 build. Sun Microsystems. 12 December 2008. http://download.java.net/jdk6/6u12/promoted/b02/changes/jdk6uN-b02.html. Läst 17 december 2008. 
  4. ^ Torre, Mario (2 March 2008). ”FINAL PROPOSAL: Portable GUI backends”. FINAL PROPOSAL: Portable GUI backends. http://mail.openjdk.java.net/pipermail/challenge-discuss/2008-March/000082.html. Läst 7 september 2008. 
  5. ^ Kennke, Roman (18 December 2008). ”Caciocavallo Architecture Overview”. Caciocavallo Architecture Overview. http://rkennke.wordpress.com/2008/12/18/caciocavallo-architecture-overview/. Läst 7 september 2008. 
  6. ^ Kennke, Roman (3 September 2008). ”Cacio Swing AWT peers”. Cacio Swing AWT peers. http://rkennke.wordpress.com/2008/09/03/cacio-swing-awt-peers/. Läst 7 september 2008. 
  7. ^ ”How much has been pushed upstream?”. How much has been pushed upstream?. openjdk.java.net. 20 September 2009. http://mail.openjdk.java.net/pipermail/caciocavallo-dev/2009-September/000184.html. Läst 7 mars 2010. ”You don't need anymore those patches, with the latest FontManager push, everything is upstream now, so just use the Cacio repo, it's completely self contained. 
  8. ^ [a b] Kennke, Roman (28 July 2011). ”JDK7 and Cacio coolness”. JDK7 and Cacio coolness. http://rkennke.wordpress.com/2011/07/28/jdk7-and-cacio-coolness/. Läst 8 augusti 2011. 
  9. ^ Eisserer, Clemens. ”HTML5/Canvas backend for Caciocavallo (GNU-Classpath)”. HTML5/Canvas backend for Caciocavallo (GNU-Classpath). Arkiverad från originalet den 10 August 2011. http://www.webcitation.org/1312943154337056. Läst 8 augusti 2011. 

Mall:Widget toolkits