Wednesday, September 26, 2018

Introduction to the AWT

Introduction

The Java programming language class library provides a user interface toolkit called Abstract Windowing Toolkit or AWT. AWT is powerful and flexible. Newcomers, however, often find their power veiled. Descriptions of classes and methods found in distributed documentation provide little guidance to the new programmer. In addition, the available examples often leave many important questions unanswered. Of course, newcomers should expect some difficulty. Effective graphical user interfaces are inherently challenging to design and implement, and the sometimes complicated interactions between classes in AWT only make this task more complex. However, with proper guidance, creating a graphical user interface using AWT is not only possible but relatively simple.


This article discusses some of the philosophies behind AWT and addresses the practical concern of how to create a simple user interface for an applet or application

What is a user interface


The user interface is the part of a program that interacts with the user of the program. User interfaces take several forms. These forms vary in complexity, from simple command-line interfaces to the point-and-click graphical user interfaces provided by many modern applications.


At the lowest level, the operating system transmits mouse and keyboard information to the program as input and provides pixels for program output. The AWT is designed so that programmers do not worry about the details of tracking the mouse or reading the keyboard, or attending to the details of recording on the screen. AWT provides a well-designed object-oriented interface for these services and low-level resources.


Since the Java programming language is independent of the platform, the AWT must also be independent of the platform. The AWT is designed to provide a common set of graphical user interface design tools that work across multiple platforms. The user interface elements provided by AWT are implemented using the native GUI toolkit of each platform, thus preserving the appearance of each platform. This is one of the strongest points of AWT. The disadvantage of this approach is the fact that a graphical user interface designed on one platform may look different when it is displayed on another platform.


Components and containers


A graphical user interface is constructed of graphic elements called components. Typical components include elements such as buttons, scroll bars, and text fields. The components allow the user to interact with the program and provide the user with visual feedback on the status of the program. In the AWT, all the components of the user interface are instances of the Component class or one of its subtypes.


The components are not alone, but they are in containers. The containers contain and control the design of the components. The containers are themselves components and, therefore, can be placed inside other containers. In the AWT, all containers are instances of the Container class or one of its subtypes.


Creating a container


Before adding the components that make up a user interface, the programmer must create a container. When building an application, the programmer must first create an instance of the Window class or the Frame class. When creating an applet, a framework already exists (the browser window). Since the Applet class is a subtype of the Panel class, the programmer can add the components to the instance of the Applet class itself.




No comments:

Post a Comment

From Java 8 to Java 11

Switching from Java 8 to Java 11 is more complicated than most updates. Here are some of my notes on the process. Modules Java 9 i...