220 likes | 378 Views
Graphical User Interface. The Abstract Window Toolkit (AWT) is a Java environment that allows applets and applications present information to the user and invite the user’s interaction using a GUI. java.awt. java.applet. Object. javax.swing. Component. Component. Others. Button. Button.
E N D
Graphical User Interface • The Abstract Window Toolkit (AWT) is a Java environment that allows applets and applications present information to the user and invite the user’s interaction using a GUI.
java.awt java.applet Object javax.swing Component Component Others Button Button Label Container Others Panel Window javax.swing.JComponent Applet Dialog Frame
The Class Component • Components are also called widgets. • Component is an abstract class that encapsulates all of the attributes of a visual component. • A Component object is responsible for remembering the current foreground and background colors and the currently selected text font.
The Class Component public abstract class java.awt.Component extends java.lang.Object implements java.awt.image.ImageObserver { public boolean action(Event evt, Object what); public boolean isVisible(); public void show(); }
The Class Frame • A Frame is a top-level window with a title and a border. • A Frame can also have a menu bar. • The AWT sends the frame all mouse, keybord, and focus events that occur over it.
The Class Frame public class java.awt.Frame extends java.awt.Window implements java.awt.MenuContainer { public Frame(); public Frame(String title); …. }
Container • Container is the abstract superclass representing all components that can hold other components. • Each container may be associated with a LayoutManager instance that determines the position of each of the container’s subcomponents.
The Class Container public abstract class java.awt.Container extends java.awt.Component { public Component add(Component comp); public Component add(Component comp, int pos); public Component add(String name, Component comp); public void setLayout(LayoutManager mgr); ……….. }
Layout Managers Layout managers allow an application to control the way in which components are arranged within a container, even if the container is resized. • FlowLayout • BorderLayout • GridLayout • CardLayout
The Interface LayoutManager public interface java.awt.LayoutManager { public abstract void addLayoutComponent( String name, Component cmp); public abstract void layoutContainer( Container parent) ….. }
The Class TextField • A text field is a component that presents the user with a single editable line of text public class java.awt.TextField extends java.awt.TextComponent { public TextField(); public TextField(int cols); public TextField(String text); public TextField(String text, int cols); }
The Class FlowLayout • A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. • Flow layouts are typically used to arrange buttons in a panel. ok open close
The Class FlowLayout public class java.awt.FlowLayout extends java.lang.Object implements java.awt.LayoutManager { public final static int CENTER = 1; public final static int LEFT = 0; public final static int RIGHT = 2; public FlowLayout(); public FlowLayout(int align); public FlowLayout(int align, int hgap, int vgap); }
The Class GridLayout public class java.awt.GridLayout extends java.lang.Object implements java.awt.LayoutManager { public GridLayout(int rows, int cols); public GridLayout(int rows, int cols, int hgap, int vgap); …. }
The Class GridLayout • The grid layout manager causes the container’s components to be laid out in a rectangular grid. • The container is split into equal-sized rectangles: one component is placed into each rectangle. • setLayout(new GridLayout(3, 2)); 1 2 3 4 5 6
The Class Button • This class creates a labeled button. The application can cause some action to happen when the button is pushed. public class java.awt.Button extends java.awt.Component { public Button(); public Button(String label); }
TheClass BorderLayout A border layout lays out a container using members named “North”, “South”, “East”, “West”, and “Center”. North East West Center South
The Class BorderLayout public class java.awt.BorderLayout extends java.lang.Object implements java.awt.LayoutManager { public BorderLayout(); public BorderLayout(int hgap, int vgap); ….. }
The Class CardLayout • A layout manager for a container the contains several “cards.” • Only one card is visible at a time, allowing the application to flip through the cards.
The Class Panel • A panel is the simplest container class. It provides space into which an application can attach any other component, including other panels. • The default layout manager for a panel is the FlowLayout.
The Class Panel public class java.awt.Panel extends java.awt.Container { public Panel(); public void addNotify(); }