Abstract Window Toolkit

Windows form with some AWT examples

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 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 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, the check box on Windows is not the same as the check box on macOS 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 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 systems.

Architecture

The AWT provides two levels of APIs:

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

Neither AWT nor Swing is 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

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 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]

Example

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyApp {

    public static void main(char[] 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);
    }
}

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.[3][4] The project has successfully implemented AWT widgets using Java2D.[5] All the necessary core-JDK modifications have since been pushed to OpenJDK 7,[6] 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[7] 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.[7][8]

See also

References

  1. ^ Fowler, Amy (1994). "Mixing heavy and light components". Sun Microsystems. Archived from the original on 23 December 2011. Retrieved 17 December 2008.
  2. ^ "Bug/RFE fixed in current JDK 6u12 build". Sun Microsystems. 12 December 2008. Archived from the original on 17 December 2008. Retrieved 17 December 2008.
  3. ^ Torre, Mario (2 March 2008). "FINAL PROPOSAL: Portable GUI backends". Archived from the original on 19 March 2012. Retrieved 7 September 2008.
  4. ^ Kennke, Roman (18 December 2008). "Caciocavallo Architecture Overview". Retrieved 7 September 2008.
  5. ^ Kennke, Roman (3 September 2008). "Cacio Swing AWT peers". Archived from the original on 13 March 2012. Retrieved 7 September 2008.
  6. ^ "How much has been pushed upstream?". openjdk.java.net. 20 September 2009. Archived from the original on 19 March 2012. Retrieved 7 March 2010. 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.
  7. ^ a b Kennke, Roman (28 July 2011). "JDK7 and Cacio coolness". Retrieved 8 August 2011.
  8. ^ Eisserer, Clemens. "HTML5/Canvas backend for Caciocavallo (GNU-Classpath)". Archived from the original on 21 March 2012. Retrieved 8 August 2011.

Read other articles:

River Where the Moon RisesPoster promosiNama alternatifMoon Rising RiverHangul달이 뜨는 강 GenreSejarahPembuatKBS Drama ProductionBerdasarkanPrincess Pyeonggangoleh Choi SagyuDitulis olehHan Ji-hoonKim Se-heeSutradaraYoon Sang-hoPemeranKim So-hyunNa In-wooLee Ji-hoonChoi Yu-hwaNegara asalKorea SelatanBahasa asliKoreaJmlh. episode20ProduksiProduser eksekutifYoon Jae-hyuk (KBS)ProduserJo Yoon-jungPengaturan kameraKamera tunggalRumah produksiVictory ContentsDistributorKBSViu OriginalRilis ...

 

Aksara SiddhamātṛkāJenis aksara Abugida BahasaSanskertaPeriodemulai sekitar 600 M, hingga 1200 M di India, dan hingga sekarang di JepangDaerahIndia, Cina, JepangAksara terkaitSilsilahMenurut hipotesis hubungan antara abjad Aramea dengan Brahmi, maka silsilahnya sebagai berikut: Abjad Proto-Sinai Abjad Fenisia Abjad Aramea Aksara Brahmi Dari aksara Brahmi diturunkanlah:Aksara GuptaAksara SiddhamātṛkāAksara turunanAksara Tibet dan keturunannyaAksara kerabatAksara NagariAksara Śāradā&...

 

David Albelda Informasi pribadiNama lengkap David Albelda AliquésTanggal lahir 1 September 1977 (umur 46)Tempat lahir La Pobla Llarga, SpanyolTinggi 181 m (593 ft 10 in)Posisi bermain Gelandang bertahanKarier junior1992–1995 AlziraKarier senior*Tahun Tim Tampil (Gol)1995–1996 Valencia B 31 (4)1996–2013 Valencia 351 (6)1996–1997 → Villarreal (pinjaman) 34 (0)1998–1999 → Villarreal (pinjaman) 35 (2)Total 451 (12)Tim nasional1996 Spanyol U-18 8 (0)1997 Spanyol...

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Handley, Fort Worth, Texas – news · newspapers · books · scholar · JSTOR (December 2009) (Learn how and when to remove this template message) A line of businesses in what once was the downtown area of Handley, Tx Handley was a town in Tarrant County, Texas, United States. It is ...

 

Radio station in McCook, NebraskaKQHKMcCook, NebraskaFrequency103.9 MHzBranding103.9 The HawkProgrammingFormatClassic rockAffiliationsPremiere Radio Networks, Westwood OneOwnershipOwnerArmada Media(Armada Media - Mccook)Sister stationsKHAQ, KXNP, KODY, KMTY, KUVR, KADL, KICX, KBRL, KFNF, KSTH, KJBLHistoryFirst air date2008Technical informationFacility ID166033ClassC2ERP50,000 wattsHAAT113 meters (371 ft)Transmitter coordinates40°10′19″N 100°41′5″W / 40.17194°N ...

 

PayanganKecamatanPeta lokasi Kecamatan PayanganNegara IndonesiaProvinsiBaliKabupatenGianyarPemerintahan • CamatI Made Widana (2021) (2009)[1]Populasi • Total42,400 jiwa (2.014)[2] 41,164 jiwa (2.010)[3] jiwaKode pos80572Kode Kemendagri51.04.07 Kode BPS5104070 Luas75,88 Km²Desa/kelurahan9 Desa Payangan adalah sebuah kecamatan di Kabupaten Gianyar, provinsi Bali, Indonesia. Berjarak 35 km dari pusat ibu kota Kabupaten Gianyar. Luasnya a...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Donja Stubica – news · newspapers · books · scholar · JSTOR (August 2011) (Learn how and when to remove this message) Town in Krapina-Zagorje, CroatiaDonja StubicaTownGrad Donja Stubica Town of Donja StubicaDonja Stubica town hallDonja StubicaLocation of Donja ...

 

Species of shark Common thresher Conservation status Vulnerable  (IUCN 3.1)[1] CITES Appendix II (CITES)[2] Scientific classification Domain: Eukaryota Kingdom: Animalia Phylum: Chordata Class: Chondrichthyes Subclass: Elasmobranchii Subdivision: Selachimorpha Order: Lamniformes Family: Alopiidae Genus: Alopias Species: A. vulpinus Binomial name Alopias vulpinus(Bonnaterre, 1788) Confirmed (dark blue) and suspected (light blue) range of the common thresher[3...

 

de Carvalho Rizzotto est un nom portugais ; le premier nom de famille (d'usage facultatif) est de Carvalho et le second est Rizzotto. Laura Rizzotto Laura Rizzotto en 2018Informations générales Nom de naissance Laura de Carvalho Rizzotto Naissance 18 juillet 1994 (29 ans)Rio de Janeiro, Brésil Activité principale Chanteuse Genre musical PopFolkRock Instruments VoixGuitareUkuléléPiano Années actives 2009 − présent Labels Unviversal Music Brazil (2010 ― 2013)Sony Musi...

  «أحمد الشقيري» تُحوِّل إلى هنا. لمعانٍ أخرى، طالع أحمد الشقيري (توضيح). أحمد الشقيري أحمد الشقيري في يوليو 2019 معلومات شخصية اسم الولادة أحمد مازن أحمد أسعد الشقيري الميلاد 6 يونيو 1973 (العمر 50 سنة)جدة، السعودية مواطنة السعودية  الأولاد يوسفإبراهيم الأب مازن الشقيري�...

 

American historian James D. TracyJames D. Tracy at the Commemorative Conference on the Siege of Szigetvár and Süleyman the Magnificent's and Miklós Zrinyi's Deaths in Hungary, September 2016BornJames Donald Tracy1938St. Louis, Missouri, U.S.NationalityAmericanSpouse Suzanne K. Swan ​(m. 1997)​Academic backgroundAlma materSaint Louis University (BA)University of Notre Dame (MA)Johns Hopkins University (MA)Princeton University (PhD)Academic workDisciplineHistoryS...

 

1996 philosophy book by David Chalmers The Conscious Mind: In Search of a Fundamental Theory CoverAuthorDavid ChalmersLanguageEnglishSubjectPhilosophy of mindPublisherOxford University PressPublication date1996Publication placeUnited StatesMedia typePrint (hardcover and paperback)Pages432ISBN978-0195117899 The Conscious Mind: In Search of a Fundamental Theory was published in 1996, and is the first book written by David Chalmers, an Australian philosopher specialising in philosophy of mi...

Cet article est une ébauche concernant Singapour et les Jeux olympiques. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Singapour aux Jeux olympiques Code CIO SIN puis SGP Comité Conseil national olympique de Singapour Participation 17 (été) ; 0 (hiver) MédaillesRang : - Or1 Arg.2 Bron.2 Total5 Historique Jeux olympiques d'été 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 200...

 

1996 Iowa Republican presidential caucuses ← 1992 February 12, 1996 (1996-02-12) 2000 →   Nominee Bob Dole Pat Buchanan Lamar Alexander Party Republican Republican Republican Home state Kansas Virginia Tennessee Popular vote 25,461 22,578 17,052 Percentage 26.31% 23.33% 17.62%   Nominee Steve Forbes Phil Gramm Alan Keyes Party Republican Republican Republican Home state New York Texas Maryland Popular vote 9,861 9,055 7,219 P...

 

AllsvenskanDatum2 april–6 november 2022Nya lag för säsongenIFK VärnamoGIF SundsvallHelsingborgs IFVinnareBK Häcken(1:a allsvenska titeln)(1:a SM-titeln)NedflyttadeHelsingborgs IFGIF SundsvallChampions LeagueBK HäckenEuropa Conference LeagueDjurgårdens IFHammarby IFStatistikSpelade matcher240Totalt antal mål662 (2,8 per match)Största hemmavinst2 matcher Djurgården 5–0 Värnamo(16 juli 2022)Häcken 5–0 Helsingborg(8 augusti 2022)Största bortavinstDegerfo...

Monti ŚnieżnikContinenteEuropa Stati Polonia Rep. Ceca Catena principaleSudeti Orientali Cima più elevataKrálický Sněžník (1 425 m s.l.m.) Superficie276 km² I Monti Śnieżnik (in polacco: Masyw Śnieżnika; in lingua ceca: Králický Sněžník; in tedesco: Glatzer Schneegebirge) sono il massiccio montuoso più alto della parte polacca dei Sudeti Orientali; sono situati in Polonia al confine con la Repubblica Ceca. Amministrativamente fanno parte del Di...

 

Para otros usos de este término, véase Pena de muerte (desambiguación). «Sentencia de muerte» redirige aquí. Para otras acepciones, véase Sentencia de muerte (desambiguación). «Pena capital» redirige aquí. Para la película danesa de 1903, véase Pena capital (película). Uso y penalización de penas de muerte en el mundo en 2024:      Abolida para todos los delitos, incluidos los crímenes de guerra.      Vigente solo para crímen...

 

Old town of Osijek, Croatia TvrđaOsijek, Croatia TvrđaCoordinates45°33′40″N 18°41′46″E / 45.561073°N 18.696093°E / 45.561073; 18.696093TypeStar fortSite informationControlled byList of rulers from its foundation to 1526 Kingdom of Hungary 1691–1744 Kingdom of Croatia within Habsburg monarchy 1744–1804 Kingdom of Slavonia within Habsburg monarchy 1804–1867 Kingdom of Slavonia within Austrian Empire 1867–1918 Kingdom of Croatia-Slavonia within ...

A Month in the CountryKonstantin Stanislavski (left) and Olga Knipper (right)as Rakitin and Natalya inthe Moscow Art Theatre's production in 1909Written byIvan TurgenevCharactersNatalya PetrovnaMikhail RakitinAleksei BelyaevVeraShpigelskyArkadi IslaevLizaveta BogdanovnaBolshintsovSchaafAnna SemenovnaKolyaKatyaMatveiDate premiered1872Original languageRussianGenreComedySettingThe Islaev country estate in the 1840s A Month in the Country (Russian: Месяц в деревне, romanized: Me...

 

Private university in Kyoto, Japan Doshisha University同志社大学Map around ImadegawaMottoLatin: Veritas liberabit vosMotto in EnglishTruth shall make you freeTypePrivateEstablishedFounded 1875, chartered 1920Endowment€1 billion (JP¥169.6 billion)PresidentMatsuoka TakashiVice-presidentNobuhiro Tabata, Yasuhiro Kuroki, Tsutao Katayama, Takashi NishimuraAcademic staff2,357 (800 full-time, 1557 part-time)Undergraduates27,024Postgraduates2,298LocationKyoto, Kyoto Prefecture,...