1 / 21

Graphical User Interface

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.

martha
Download Presentation

Graphical User Interface

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. java.awt java.applet Object javax.swing Component Component Others Button Button Label Container Others Panel Window javax.swing.JComponent Applet Dialog Frame

  3. 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.

  4. 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(); }

  5. 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.

  6. The Class Frame public class java.awt.Frame extends java.awt.Window implements java.awt.MenuContainer { public Frame(); public Frame(String title); …. }

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

  8. 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); ……….. }

  9. 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

  10. The Interface LayoutManager public interface java.awt.LayoutManager { public abstract void addLayoutComponent( String name, Component cmp); public abstract void layoutContainer( Container parent) ….. }

  11. 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); }

  12. 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

  13. 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); }

  14. 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); …. }

  15. 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

  16. 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); }

  17. TheClass BorderLayout A border layout lays out a container using members named “North”, “South”, “East”, “West”, and “Center”. North East West Center South

  18. The Class BorderLayout public class java.awt.BorderLayout extends java.lang.Object implements java.awt.LayoutManager { public BorderLayout(); public BorderLayout(int hgap, int vgap); ….. }

  19. 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.

  20. 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.

  21. The Class Panel public class java.awt.Panel extends java.awt.Container { public Panel(); public void addNotify(); }

More Related