ANU The Australian National University



____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

COMP2100/2500
Lecture 11: Graphical User Interfaces I

Summary

The first of three lectures on graphical user interfaces, introducing some fundamental concepts and definitions.

Aims

Outline

Today

GUI II:

GUI III:


Structure of graphical applications


Model-View-Controller architecture

This is a very common architecture for GUI programming. In Java, particularly if listeners are written as inner classes, it can become muddled. But it's still a useful way to organise your thinking.

  1. Model - the core application part

    • underlying data, functional core of application

    • registers dependent views and controllers

    • notifies views and controllers of changes to data

  2. View - the graphical part of the interface

    • creates its controllers

    • displays information (about the model) to the user

    • updates itself when the model changes

    • retrieves data from the model

  3. Controller - the decision-making part

    • accepts user inputs and other events

    • translates events into service requests for the model or display requests for the view


Events

Types of events:

Example: the expose event for a window

Other important window events include mouse in, mouse out, mouse button down, mouse button up, keys pressed


How to handle events

Polling:

Callbacks:


GUI concepts

widget

a GUI component like a window, a push button, a label, a scroll-bar, a menu item...

pixel

a single dot on the display screen

displays are typically 800×600, 1024×768, 1280×1024 pixels

depth

the number of bits per pixel

  • depth 1 = black & white

  • depth 8 = 256 colours

  • depth 24 = 16,777,216 colours

colour map

translation between pixel values and actual screen colours on a low-depth display

bitmap

an image one pixel deep

pixmap

an image of arbitrary depth (effectively as a two-dimensional array of pixels, although you may not be able to access them like array elements)

font

a mapping from characters to bitmaps


More about widgets

Widgets are ready-made low-level (and not-so-low-level) components provided by the underlying library (e.g. Motif, MFC, GTK+, Java AWT, Java Swing etc)

Examples of widgets include:

  • labels

  • separators

  • push-buttons

  • toggle-buttons

  • radio buttons

  • spin buttons

  • scale widgets

  • scroll-bars

  • text widgets

  • text-field widgets

  • list widgets

  • progress bars

  • menu-bars

  • menus

  • menu-items

  • tree widgets

  • message boxes

  • scrolled areas

  • forms

  • frames

  • dialog boxes

  • status bars

  • toolbars


Crash course on GUI design

Before we start building them, let's spend a few minutes thinking about what we're trying to build and why.

Common user interface problems


User interface guidelines


Further reading


The Java GUI libraries

First there was the Abstract Windowing Toolkit (AWT). A little later its drawing capabilities were extended by the Java2D API. Later still came Swing.

Most Swing components are pure Java components or so-called lightweight components. That is, they are written completely in Java. AWT components are implemented natively on each different platform that supports Java. Somewhere deep down in the implementation, there is a bridge to the system's native graphics routines. Obviously this is different on Linux, Windows, Macintosh etc. As a result, these heavyweight components look different on different platforms.

There is full documentation for all the Java GUI classes in the API documentation. The AWT classes are in the packages java.awt and the corresponding event handling classes are in java.awt.event. The Swing classes are in javax.swing with event handling in javax.swing.event. Unfortunately many of the Java GUI classes have very large and confusing interfaces so that it can be hard to figure out what are the useful bits and what parts you can safely ignore.

Java Swing (backed up by AWT) provides a rich set of GUI features including pluggable look and feel, shortcut keys, tool tips, support for assistive technologies and for localisation (or internationalisation). We won't have time to cover anything like all of it, but we'll do enough to get you started writing realistic graphical user interfaces.

____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

Copyright © 2005, Ian Barnes, The Australian National University
Version 2005.1, Tuesday, 15 March 2005, 23:34:00 +1100
Feedback & Queries to comp2100@cs.anu.edu.au