Page 1 :
1.Abstract Windowing Toolkit(AWT), 12 Marks, Prof. Ghanawajeer D.J.
Page 2 :
Unit Outcomes(UOs), a), , Develop Graphical user interface (GUI) programs using, AWT components for the given problem., , b) Create Frame window with the specified AWT components., c) Arrange the GUI components using specified layout, manager., d) Develop a program using Menu and Dialog Boxes for the, given problem., 2
Page 3 :
Abstract Window Toolkit, • The AWT contains numerous classes and methods, that allow us to create and manage windows., • Although the main purpose of the AWT is to support, applet windows, it can also be used to create standalone windows that run in a GUI environment, such, as Windows., 3
Page 4 :
AWT Classes, • The AWT classes are contained in the java.awt, package. It is one of Java’s largest packages., • Fortunately, because it is logically organized in a topdown, hierarchical fashion, it is easier to understand, and use than you might at first believe., , 4
Page 5 :
AWT Classes, Class, , Description, , AWTEvent, , Encapsulates AWT events., , BorderLayout, , The border layout manager. Border layouts use five, components: North, South, East, West, and Center., , Button, , Creates a push button control., , Canvas, , A blank, semantics-free window., , CardLayout, , The card layout manager. Card layouts emulate index, cards. Only the one on top is showing., , Checkbox, , Creates a check box control., , CheckboxGroup, , Creates a group of check box controls., 5
Page 6 :
AWT Classes, Class, , Description, , CheckboxMenuItem, , Creates an on/off menu item., , Choice, , Creates a pop-up list., , Color, , Manages colors in a portable, platform-independent, fashion., , Component, , An abstract super-class for various AWT components., , Container, , A subclass of Component that can hold other, components., , Cursor, , Encapsulates a bitmapped cursor., , Dialog, , Creates a dialog window., 6
Page 7 :
AWT Classes, Class, , Description, , Dimension, , Specifies the dimensions of an object. The width is stored, in width, and the height is stored in height., , Event, , Encapsulates events., , FileDialog, , Creates a window from which a file can be selected., , FlowLayout, , The flow layout manager. Flow layout positions, components left to right, top to bottom., , Font, , Encapsulates a type font., , FontMetrics, , Encapsulates various information related to a font. This, information helps you display text in a window., , 7
Page 8 :
AWT Classes, Class, , Frame, Graphics, GraphicsEnvironment, GridBagConstraints, GridBagLayout, GridLayout, , Description, , Creates a standard window that has a title bar, resize, corners, and a menu bar., Encapsulates the graphics context. This context is used by, the various output methods to display output in a window., Describes the collection of available Font and, GraphicsDevice objects., Defines various constraints relating to the, GridBagLayout class., The grid bag layout manager. Grid bag layout displays, components subject to the constraints specified by, GridBagConstraints., The grid layout manager. Grid layout displays, 8, components in a two-dimensional grid.
Page 9 :
AWT Classes, Class, , Description, , Image, , Encapsulates graphical images., , Insets, , Encapsulates the borders of a container., , Label, , Creates a label that displays a string., , List, , Creates a list from which the user can choose. Similar to, the standard Windows list box., , Menu, , Creates a pull-down menu., , MenuBar, , Creates a menu bar., , MenuComponent, , An abstract class implemented by various menu classes., 9
Page 10 :
AWT Classes, Class, , Description, , MenuItem, , Creates a menu item., , Panel, , The simplest concrete subclass of Container., , Scrollbar, , Creates a scroll bar control., , TextArea, , Creates a multiline edit control., , TextComponent, , A superclass for TextArea and TextField., , TextField, , Creates a single-line edit control., , Window, , Creates a window with no frame, no menu bar., 10
Page 12 :
1.1. Component, Container, Window, Frame, Panel, • The AWT defines windows according to a class, hierarchy that adds functionality and specificity with, each level., • The two most common windows are those derived, from Panel, which is used by applets, and those, derived from Frame, which creates a standard window., 12
Page 13 :
1.1. Component, Container, Window, Frame, Panel, • Much of the functionality of these windows is derived, from their parent classes. Thus, a description of the, class hierarchies relating to these two classes is, fundamental to their understanding., , 13
Page 14 :
1.1. Component, Container, Window, Frame, Panel, Component, , Container, , Window, , Frame, , Panel, , Dialog, , Applet, 14
Page 15 :
1.1. Component, Container, Window, Frame, Panel, Component:, • At the top of the AWT hierarchy is the Component, class. Component is an abstract class that encapsulates, all of the attributes of a visual component., , 15
Page 16 :
1.1. Component, Container, Window, Frame, Panel, Component:, • All user interface elements that are displayed on the, screen and that interact with the user are subclasses of, Component. It defines over a hundred public methods that, are responsible for managing events, such as mouse and, keyboard input, positioning and sizing the window, and, repainting., , 16
Page 17 :
1.1. Component, Container, Window, Frame, Panel, Component:, • A Component object is responsible for remembering, the current foreground and background colors and the, currently selected text font., , 17
Page 19 :
1.1. Component, Container, Window, Frame, Panel, Container:, • The Container class is a subclass of Component. It, has additional methods that allow other Component, objects to be nested within it., , 19
Page 20 :
1.1. Component, Container, Window, Frame, Panel, Container:, • Other Container objects can be stored inside of a, Container (since they are themselves instances of, Component)., , This, , makes, , for, , a, , multileveled, , containment system., , 20
Page 21 :
1.1. Component, Container, Window, Frame, Panel, Container:, • A container is responsible for laying out (that is,, positioning) any components that it contains. It does, this through the use of various layout managers., , 21
Page 22 :
1.1. Component, Container, Window, Frame, Panel, Container:, • The Container class defined all the data and methods, necessary for managing groups of Components, ▫, ▫, ▫, ▫, ▫, ▫, ▫, , add, getComponent, getMaximumSize, getMinimumSize, getPreferredSize, remove, removeAll, , 22
Page 23 :
1.1. Component, Container, Window, Frame, Panel, , 23
Page 24 :
1.1. Component, Container, Window, Frame, Panel, Panel:, • The Panel class is a concrete subclass of Container., • It doesn’t add any new methods; it simply implements, Container. A Panel may be thought of as a recursively, nestable, concrete screen component., , 24
Page 25 :
1.1. Component, Container, Window, Frame, Panel, Panel:, • Panel is the super-class for Applet. When screen output is, directed to an applet, it is drawn on the surface of a Panel, object. In essence, a Panel is a window that does not, contain a title bar, menu bar, or border. This is why we, don’t see these items when an applet is run inside a, browser., 25
Page 26 :
1.1. Component, Container, Window, Frame, Panel, Panel:, , • When we run an applet using an applet viewer, the applet, viewer provides the title and border. Other components can, be added to a Panel object by its add( ) method (inherited, from Container). Once these components have been added,, we can position and resize them manually using the, setLocation( ), setSize( ), or setBounds( ) methods defined, by Component., 26
Page 27 :
1.1. Component, Container, Window, Frame, Panel, Window:, • The Window class creates a top-level window. A toplevel window is not contained within any other object;, it sits directly on the desktop. Generally, we won’t, create Window objects directly. Instead, we will use a, subclass of Window called Frame., 27
Page 28 :
1.1. Component, Container, Window, Frame, Panel, Frame:, • Frame encapsulates what is commonly thought of as a, “window.”, • It is a subclass of Window and has a title bar, menu bar,, borders, and resizing corners. If we create a Frame object from, within an applet, it will contain a warning message, such as, “Java Applet Window,” to the user that an applet window has, been created., 28
Page 29 :
1.1. Component, Container, Window, Frame, Panel, Frame:, • This message warns users that the window they see, was started by an applet and not by software running, on their computer., • When a Frame window is created by a program rather, than an applet, a normal window is created., 29
Page 30 :
1.1. Component, Container, Window, Frame, Panel, , 30
Page 31 :
1.1. Component, Container, Window, Frame, Panel, Canvas:, • Canvas encapsulates a blank window upon which, we can draw., , 31
Page 32 :
1.1. Component, Container, Window, Frame, Panel, Dimension:, • This class encapsulates the ‘width’ and ‘height’ of a, component (in integer precision) in a single object., • The class is associated with certain properties of, components. Several methods defined by the Component, class and the LayoutManager interface return a Dimension, object., 32
Page 33 :
1.1. Component, Container, Window, Frame, Panel, Dimension:, • Normally the values of width and height are non-negative, integers. The constructors that allow us to create a, dimension do not prevent us from setting a negative value, for these properties., • If the value of width or height is negative, the behavior of, some methods defined by other objects is undefined., 33
Page 34 :
1.1. Component, Container, Window, Frame, Panel, Fields of Dimension:, • int height-The height dimension; negative values can, be used., • int width-The width dimension; negative values can be, used., , 34
Page 35 :
1.1. Component, Container, Window, Frame, Panel, Constructors of Dimension:, • Dimension(), ▫ It creates an instance of Dimension with a width of zero, and a height of zero., • Dimension(Dimension d), ▫ It creates an instance of Dimension whose width and, height are the same as for the specified dimension., 35
Page 36 :
1.1. Component, Container, Window, Frame, Panel, Constructors of Dimension:, • Dimension(int width, int height), ▫ It constructs a Dimension and initializes it to the specified, width and specified height., , 36
Page 37 :
1.1. Component, Container, Window, Frame, Panel, Methods of Dimension:, • boolean equals(Object obj)- It checks whether two dimension, objects have equal values., • double getHeight()- It returns the height of this dimension in, double precision., • Dimension getSize()- It gets the size of this Dimension object., • double getWidth()- It returns the width of this dimension in, double precision., , 37
Page 38 :
1.1. Component, Container, Window, Frame, Panel, Methods of Dimension:, • void setSize(Dimension d)- It sets the size of this, Dimension object to the specified size., • void setSize(double width, double height)- It sets the size, of this Dimension object to the specified width and height, in double precision., • void setSize(int width, int height)- It sets the size of this, Dimension object to the specified width and height., , 38
Page 39 :
1.1. Component, Container, Window, Frame, Panel, Example of Dimension:, , 39