ch11-ch12

Cards (90)

  • Graphical User Interface (GUI)

    One variety of user interfaces where user interacts with objects on the screen (icons, buttons, scroll-bars, etc.) via mouse clicks or keyboard actions
  • There is no specific order that a user must follow while providing input. This requires our program to carefully watch the user actions and then react accordingly.
  • Basic constructs or steps of GUI
    • Containers
    • Layout Managers
    • Components
    • Event Handlers
  • Containers
    Special components that may contain other components
  • Layout Managers

    To arrange items, one could specify the location of a component by specific x and y coordinates or the direction
  • Components
    Most interactions in a Java GUI are with Components. Another generic term for Component in other GUIs (e.g. X Windows) is "widget"
  • Different types of components
    For different types of interaction (e.g. buttons, menus, lists, etc.)
  • User interactions with components

    Create events (thus, allow event-driven programming)
  • Event Handlers
    Design human/computer dialog, using listeners and component-generated events
  • AWT: Abstract Windowing Toolkit
  • Swing: Java 2 introduced Swing classes
  • Many AWT components have improved Swing counterparts
  • Swing does not generally replace the AWT; we still use AWT events and the underlying AWT event processing model
  • AWT class hierarchy (subset) and swing
    • java.awt - The Abstract Windowing Toolkit
    • Component
    • Container
    • Window
    • Frame
    • Panel
    • Applet
  • Component
    • An abstract class, superclass of all GUI components except menu components and class CheckboxGroup
  • Container
    • The superclass for all components that contain other components, defines add(), for adding components to a container
  • Window
    • A top-level window with no border or menu bar, rarely instantiated (its subclasses are more useful)
  • Frame
    • A window with a title bar and can have a menu bar, top-level window for Java AWT-based applications
  • Panel
    • A container that must be contained within another container, does not have its own window
  • Applet
    • A subclass of Panel, actually part of the java.applet package, not the AWT
  • AWT Limitations: "look and feel" of AWT-based programs differs slightly across platforms, because of differences in the underlying native GUI elements
  • AWT components limited to those that are available on all platforms (lowest common denominator)
  • Differences between Java AWT and Java Swing
    • AWT components are platform-dependent, Swing components are platform-independent
    • AWT components are heavyweight, Swing components are lightweight
    • AWT doesn't support pluggable look and feel, Swing supports pluggable look and feel
    • AWT provides less components than Swing, Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.
    • AWT doesn't follows MVC(Model View Controller) where model represents data, view represents presentation and controller acts as an interface between model and view, Swing follows MVC
  • javax.swing - The Swing Toolkit
  • Swing components do not require native peer components, each Swing UI component is painted onto a blank window
  • Swing GUI components
    • labels (including images)
    • text fields and text areas
    • buttons
    • check boxes
    • radio buttons
    • menus
    • combo boxes
    • and many more...
  • Labels
    Used to provide information to the user or to add decoration to the GUI, defined by the JLabel class
  • Buttons
    GUI buttons fall into various categories: push button, check box, radio buttons
  • Radio Buttons
    A set of buttons that provide a set of mutually exclusive options, must work as a group where only one can be toggled on at a time, grouped using the ButtonGroup class
  • Combo Boxes
    Display a particular option with a pull down menu from which the user can choose a different option, can be editable so that the user can type their option directly into the box
  • JTextField
    Used to get text input from the user, can get the text, set the text, add an ActionListener to listen for when the user presses return or enter
  • JTextArea
    Used to display multi-line text, can be placed in a JScrollPane to add scrollbars
  • JCheckBox
    A checkbox that can be toggled on or off, can listen for item events when it is selected or deselected
  • JList
    A list of items that the user can select from, can be placed in a JScrollPane to add scrollbars
  • By default, a frame is sized at 0x0 pixels, so setSize() is sent to the frame to change it size</b>
  • The show() method is deprecated, use setVisible(true) instead
  • Event-Driven GUI
    Java Virtual Machine watches for the user's actions on components and creates event objects that correspond to these actions, sends these event objects to listeners which are provided by the program to handle the events
  • Event Listeners
    • MouseListener
    • ActionListener
    • MouseMotionListener
    • KeyListener
  • java.awt.AWTEvent extends EventObject and is the superclass of all Java 1.1 AWT events
  • Swing adds additional event classes, but uses the Java 1.1 event model