Abstract Window Toolkit

Abstract Window Toolkit . (AWT, in Spanish Abstract Window Toolkit). Set of GUI tools (Graphical User Interface) designed to work with multiple platforms. User interface and window system independent of the original Java programming language platform . AWT is part of the Java Foundation Classes (JFC) – the standard API for supplying a graphical user interface ( GUI ) for a Java program.

Summary

[ hide ]

  • 1 JFC graphics packages
  • 2 AWT Classes
  • 3 Component Class
    • 1 Component size and position
    • 2 Actions on the component
    • 3 User interaction events
  • 4 Container Class
  • 5 Print managers
  • 6 Other classes
    • 1 Container Classes (Container’s Daughters)
    • 2 Component classes (direct daughters of Component)
  • 7 AWT Events
    • 1 Physical events
    • 2 Semantic events
  • 8 See also
  • 9 Sources
  • 10 External links

JFC graphics packages

The JFC ( Java Foundation Classes ) are part of the API of Java composed of classes that are used to create visual graphics interfaces for applications and applets Java.

Just as Sun presents these JFCs, Microsoft has developed its own package with the name of AFD (Application Foundation Classes).

JFCs contain two graphics packages: AWT and Swing .

  • AWT: It presents heavy components, which in each platform can only have a certain representation. It is available since version 1.1 of the JDK as java.awt.
  • Swing: It presents light components, which can take different aspect and behavior since they take it from a class library. It is available since version 1.2 of the JDK as javax.swing although earlier versions such as com.sun.java could be found before. or as java.awt.swing.

AWT classes

AWT class hierarchy

This package is included in the Java API as java.awt since its first version, so the interfaces generated with this library work in all available Java environments (including browsers, which makes them especially efficient for creating applets. Java).

  • Component: This class represents any object that can be part of a graphical user interface. It is the parent class of many of the AWT classes.

Its main purpose is to represent something that has a position and a size, that can be drawn on the screen and that can receive input events (that respond to interactions with the user).

  • Container: The Container class knows how to display embedded components (which in turn can be instances of the Container class).

These Container objects have an associated LayoutManager that defines the way in which the component objects will be positioned inside them.

  • LayoutManager and LayoutManager2: they are two interfaces in charge of the representation and on-screen positioning of AWT components.
  • Other classes: Of course AWT is not limited to these classes. Within this library we can find a multitude of pre-made classes to facilitate graphic design.

Component class

Its main purpose is to represent something that has a position and a size, that can be drawn on the screen and that can receive input events (that respond to interactions with the user).

The Component class presents various methods, organized to cover various purposes.

Some of them are explained below.

Component size and position

  • Dimension getSize (); Returns the width and height of the component as an object of the Dimension class, whose fields are: width (width) and heigth (height).
  • void setSize (int width, int length); Sets the width and height of the component.
  • Dimension getPreferredSize (); Returns the size that this component should be.
  • void setPreferredSize (); Sets the size that this component should be.
  • Dimension getMinimumSize (); Returns the minimum size this component should be.
  • void setMinimumSize (int width, int int); Sets the minimum size that this component should be.
  • Rectangle getBounds (); Returns the coordinates of this component as an object of the Rectangle class, whose fields are: x, y, width and heigth.
  • void setBounds (int x, int y, int int, int int); Set the coordinates of this component.

Actions on the component

  • boolean getEnabled (); Check if the component is active or not.
  • void setEnabled (boolean); Set the component to active or inactive.
  • boolean getVisible (); Check if the component is visible or not.
  • void setVisible (boolean); Sets whether the component is visible or invisible.
  • void paint (Graphics g); Tells the AWT to draw component g.
  • void repaint (); Tells the AWT to redraw the component.
  • void update (Graphics g); It is called by AWT when the repaint () method is invoked. By default it calls paint ().

User interaction events

In turn, there are three types of methods for managing events using the new AWT event model (since version 1.1).

There are three types of methods:

  • void add_Tipo_Listener (_Tipo_Listener l); Add a listener to the wait for some kind of events about this component.
  • void remove_Tipo_Listener (_Tipo_Listener l); Delete any listener that was waiting for some kind of events on this component.
  • void process_Tipo_Event (_Tipo_Event e); Processes events of type _Type_Event by sending them to any _Type_Listener object that was listening.

In these _Type_ methods it can be any of the following:

Component, Focus, InputMethod, Key, Mouse, MouseMotion.

Container class

The Container class knows how to display embedded components (which in turn can be instances of the Container class).

Some of the methods of the Container class are:

  • Component add (Component c); Add a component to the container.
  • void print (Graphics g); Print the container.
  • void printComponents (Graphics g); Print each of the components in this container.
  • LayoutManager getLayout (); Returns the print manager (LayoutManager) associated with this container, which is responsible for placing the components inside the container.
  • void setLayout (LayoutManager 1); Set a print manager for this component.

These Container objects have an associated LayoutManager that defines the way in which the component objects will be positioned inside them.

Print managers

LayoutManager and LayoutManager2 are two interfaces responsible for the on-screen representation and positioning of AWT components.

Of these interfaces, five implementations are provided in AWT. Each of them distributes the objects in a particular way:

  • BorderLayout: In five places: North, South, East, West and Center (North, South, East, West and Center).
  • CardLayout: Allows you to manage several components of which only one is displayed at a time, while the rest are invisible below.
  • FlowLayout: From left to right horizontally on each line. When they pass one line, start to the left of the next one.
  • GridLayout: It is a table in which all the squares have the same size.
  • GridBagLayout: It is a table, but the boxes do not have to be the same size.

Other classes

Within this library we can find a multitude of pre-made classes to facilitate graphic design.

Below we explain some of them.

Container classes (Container’s daughters)

  • Panel: Lets you make a more advanced presentation than Container by combining with subpanels or subclasses to create custom containers. The Applet class used to create Java applets inherits from this Panel class.
  • ScrollPane: A scroll bar, horizontal or vertical.
  • Window: A window without a border.
  • Frame: A window that has no border. You can have an associated Menubar object (a custom toolbar or menu bar).
  • Dialog: A window used to create dialogs. It has the ability to be modal, so only this container would receive user input.
  • Filedialog: A dialog that uses the native file selector of the operating system.

Component classes (direct daughters of Component)

  • Button: A graphical button for which you can define an action that will occur when the button is pressed.
  • Canvas: Allows you to paint or capture user events. It can be used to create graphics or as a base class to create a hierarchy of custom components.
  • Checkbox: Supports two states: on and off. You can associate actions that are executed (triggers) when the state changes.
  • Choice: Drop-down menu of options.
  • Label: Label string in a given location.
  • List: A drop-down list of strings.
  • Scrollbar: Dropdown of Canvas objects.
  • TextComponent: Any component that allows editing text strings. It has two daughter classes:
  • TextField: A text component consisting of one line that can be used to build forms.
  • TextArea: Component for editing text of variable size.

AWT events

AWT has its own events, which are explained below.

Physical events

They are all children of the ComponentEvent event, which indicates some change in a Component object:

  • InputEvent: User input has occurred. It has children events KeyEvent (keystroke) and MouseEvent (action on the mouse).
  • FocusEvent: Alerts the program that the component has gained or lost the user’s attention (focus). This follows from user activity (mouse and keyboard).
  • WindowEvent: Notifies the program that the user has used one of the window controls at the operating system level, such as the minimize or close controls.
  • ContainerEvent: Sent when components are added or removed to a container.
  • PaintEvent: Special event that signals that the operating system wants to redraw a part of the interface. A component must override the paint () method or the update () method to handle this event.

Semantic events

They are all children of the AWTEvent event, which is the base event of the event hierarchy:

  • ActionEvent: Warns the program of component-specific actions such as button presses.
  • AdjustmenteEvent: Communicates that a scroll bar has been adjusted.
  • ItemEvent: Warns the program when the user interacts with a choice, a list or a check box.
  • TextEvent: Warns when a user changes text in a TextComponent, TextArea, or TextField component.
  • InputMethodEvent: Warns that a text being created using an input method is changing (something else has been written …).
  • InvocationEvent: This event executes the run () method on a Runnable class when it is handled by the AWT dispatcher thread.

 

by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment