Rice University - Comp 212 - Intermediate Programming

Fall 2001

Lecture #15 - Java Graphical User Interfaces ("GUI"s) and the Model-View-Controller ("MVC")


Java uses two main packages to manage graphical user interfaces:

  1. java.awt -- "AWT" stands for "Abstract Windowing Toolkit". This holds the base classes used to manipulate the screen. It is outmoded however and has been largely replaced with the Swing package.
    1. java.awt.event -- a sub-package that holds classes used for the events in the AWT.
  2. javax.swing -- "Swing" refers to who knows what. Some say that it refers to the transition from AWT to something better. It holds many replacement classes for the old AWT. Use Swing instead of AWT when given a choice

The Java GUI system is an Event-Driven System, which means that it does not work in the usual "start-here-go-to there-and-end-somewhere-else" type format. Instead it essentially just sits around, waiting for "events" to occur. Examples of events are:

For a GUI component (such as a button) to respond to a GUI event, we must register the event with the GUI component by adding an "event listener" to the component. We will explain later how to do that in many examples. When an event occurs, then the Java GUI system (not the user's program!) calls a corresponding method on a corresponding object.

First, let's discuss the classes involved:

Components:

Communicating with GUI components