The Java classes for graphical user interfaces are arranged in two packages, known as AWT (java.awt) and Swimg (javax.swing). The model is complicated and powerful and we don't try to explain it in detail here. Instead, we provide boiler-plate examples and common idioms.
The exercise is to draw a bar chart, looking like this:

from a data file which the user selects using the Open item of the File menu. We will do this in stages.
Look at the program BarChartAxes.java, which simply draws the axes and a single block:

You can do the first exercise now if you want to.
Look at the program BarChartEvents.java. It adds a File menu to our Frame, and an item Exit.
Look at the program MyClickExample.java.
It displays a frame consisting of some tiles. The program detects where the
user clicks, and reports which tile it corresponds to.
MouseAdapter implements the MouseListener
interface, and defines empty methods mouseClicked(), mouseEntered()
etc. We extend MouseAdapter, overriding the methods (in this
case, MouseClicked) that we are interested in defining.MouseAdapter is an anonymous inner class.
© 2001 Mark Ryan and Alan Sexton