Content deleted Content added
foldoc attribution Template_talk:FOLDOC#It_doesn't_matter_whether_readers_care |
|||
(48 intermediate revisions by 38 users not shown) | |||
Line 1:
{{Short description|Java-based GUI toolkit}}
{{Use dmy dates|date=June 2021}}
[[File:Easy Java AWT example.jpg|thumb|250px|Windows form with some AWT examples]]
The '''Abstract Window Toolkit''' ('''AWT''') is [[Java (programming language)|Java]]'s original platform-dependent [[Windowing system|windowing]], [[graphic]]s, and [[user-interface]] [[widget toolkit]], preceding [[Swing (Java)|Swing]]. The AWT is part of the [[Java Foundation Classes]] (JFC) — the standard [[Application programming interface|API]] for providing a [[graphical user interface]] (GUI) for a Java program.<ref name="foldoc">{{foldoc|Abstract+Window+Toolkit}}</ref> AWT is also the GUI toolkit for a number of [[Java Platform, Micro Edition|Java ME]] profiles. For example, [[Connected Device Configuration]] profiles require Java [[software execution|runtime]]s on [[mobile telephone]]s to support the Abstract Window Toolkit.
== 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,
In [[Java Platform, Standard Edition|J2SE 1.2]], the [[Swing (Java)|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 the native platform's [[Look and feel#Look and Feel in Widget Toolkits|"look and feel"]] or a cross-platform look and feel (the "Java Look and Feel") that looks the same on all windowing systems.
Line 18:
** Several [[layout manager]]s;
** The interface to [[input device]]s such as [[Mouse (computing)|mouse]] and [[Keyboard (computing)|keyboard]]; and
** A {{Javadoc:SE|package=java.awt.datatransfer|java/awt/datatransfer|module=java.desktop}} [[Java package|package]] for use with the [[Clipboard (software)|Clipboard]] and [[Drag and drop|Drag and Drop]].
* A basic set of GUI widgets such as buttons, text boxes, and menus. It also provides the [[Java AWT Native Interface|AWT Native Interface]], which enables [[Rendering (computer graphics)|rendering]] [[library (computer science)|libraries]] compiled to [[native code]] to draw directly to an AWT {{Javadoc:SE|java/awt|Canvas|module=java.desktop}} [[object (computer science)|object]] drawing surface.
AWT also makes some higher level functionality available to applications, such as:
Line 25:
* The ability to launch some desktop applications such as [[web browser]]s and [[Mail client|email clients]] from a Java application.
Neither AWT nor Swing
== Mixing AWT and Swing components ==
Where there is a Swing version of an AWT component it will begin with J- and should be used exclusively, replacing the AWT version. For example, in Swing, only use JButton, never Button class. As mentioned above, the AWT core classes, such as Color and Font, are still used as-is in Swing.
When drawing in Swing, use JPanel and override paintComponent(Graphics g) instead of using the AWT paint() methods.
Before [[Java version history#Java SE 6|Java 6 Update 12]], mixing [[Swing (Java)|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 [[Container (data structure)#Graphic containers|containers]] from AWT.<ref>{{cite web
|url=http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
|title=Mixing heavy and light components
|year=1994
|last=Fowler
|first=Amy
|publisher=[[Sun Microsystems]]
|access-date=17 December 2008
|archive-url=https://web.archive.org/web/20111223035101/http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
|archive-date=23 December 2011
|url-status=live
}}</ref>
Starting in [[Java version history#Java SE 6|Java 6 Update 12]], it is possible to mix Swing and AWT widgets without having z-order problems.<ref>{{cite web
|url=http://download.java.net/jdk6/6u12/promoted/b02/changes/jdk6uN-b02.html
|title=Bug/RFE fixed in current JDK 6u12 build
|date=12 December 2008
|publisher=[[Sun Microsystems]]
|access-date=17 December 2008
|url-status=dead
|archive-url=https://web.archive.org/web/20081217062847/http://download.java.net/jdk6/6u12/promoted/b02/changes/jdk6uN-b02.html
|archive-date=17 December 2008
}}</ref>
== Example ==
<syntaxhighlight lang="java">
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public static void main(String[] args) {
Frame frame = new Frame("Application");
frame.add(new Label("Hello!"));
frame.setSize(500, 500);
frame.setLocationRelativeTo(null); // Centers the window
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
frame.dispose(); // Releases native screen resources
}
});
frame.setVisible(true);
}
}
</syntaxhighlight>
== Implementation ==
Line 86 ⟶ 88:
A new project, [http://hg.openjdk.java.net/caciocavallo/caciocavallo/raw-file/tip/cacio-docs/index.html Caciocavallo], has been created, that provides an [[OpenJDK]]-based Java API to ease AWT implementation on new systems.<ref>{{cite web
|
|
|
|
|first=Mario |access-date=7 September 2008
|archive-url=https://web.archive.org/web/20120319173058/http://mail.openjdk.java.net/pipermail/challenge-discuss/2008-March/000082.html
|archive-date=19 March 2012
|url-status=live
}}</ref><ref>{{cite web
| url=http://rkennke.wordpress.com/2008/12/18/caciocavallo-architecture-overview/
| title = Caciocavallo Architecture Overview
| date = 18 December 2008
| last=Kennke|first=Roman
|
| |
|
|
|first=Roman |access-date=7 September 2008
|archive-url=https://web.archive.org/web/20120313203649/http://rkennke.wordpress.com/2008/09/03/cacio-swing-awt-peers/
|archive-date=13 March 2012
|url-status=live
}}</ref> All the necessary core-JDK modifications have since been pushed to [[OpenJDK|OpenJDK 7]],<ref>{{cite web
|url=http://mail.openjdk.java.net/pipermail/caciocavallo-dev/2009-September/000184.html
|title=How much has been pushed upstream?
|date=20 September 2009
|publisher=openjdk.java.net
|quote=''You don't need anymore of those patches, with the latest FontManager push, everything is upstream now, so just use the Cacio repo, it's completely self contained.''
|access-date=7 March 2010
|archive-url=https://web.archive.org/web/20120319173102/http://mail.openjdk.java.net/pipermail/caciocavallo-dev/2009-September/000184.html
|archive-date=19 March 2012
|url-status=live
}}</ref> 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<ref name="rkennkeDirectFB">{{cite web
| url=http://rkennke.wordpress.com/2011/07/28/jdk7-and-cacio-coolness/
| title=JDK7 and Cacio coolness
| date=28 July 2011
|
| last=Kennke|first=Roman}}</ref> 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.<ref name="rkennkeDirectFB" /><ref>{{cite web
|
|title=HTML5/Canvas backend for Caciocavallo (GNU-Classpath)
|access-date=8 August 2011
|last=Eisserer
|first=Clemens
|archive-url=https://web.archive.org/web/20120321144746/http://www.google-melange.com/gsoc/project/google/gsoc2011/linuxhippy/11001
|archive-date=21 March 2012
|url-status=dead
}}</ref>
== See also ==
{{Portal|
* [[Swing (Java)]]
* [[Standard Widget Toolkit]]
== References ==
{{
== External links ==
{{Wikibooks|Java Swings/AWT}}
{{Commons
* {{Javadoc:SE|package=java.awt|java/awt|module=java.desktop}} (AWT [[Javadoc]] API documentation)
* {{Javadoc:SE-guide|awt|AWT documentation}}
*[https://web.archive.org/web/20161215114326/http://www.java-forums.org/awt-swing/ AWT/Swing]
*[http://www.java-tips.org/java-se-tips-100019/21-java-awt.html java.awt] {{Webarchive|url=https://web.archive.org/web/20160829004424/http://www.java-tips.org/java-se-tips-100019/21-java-awt.html |date=29 August 2016 }}
{{Java desktop}}
{{Widget toolkits}}
[[Category:Articles with example Java code]]
[[Category:JDK components]]
[[Category:Widget toolkits]]
|