Java Advanced Programming Exercise 2

ScrollPane and Java 1.1 Event Model

Use the classes "DateValueVector" and "DateValueObject" from the previous exercise in a program that displays a date/value graph for the date/value data found in the text file whose name is given as a command line parameter (Exc2DateValues.txt included).

Create one public class called "DateValueGraphPanel" that extends the "Panel" class. This class contains a main-function which (without error checking for command line parameters) could look like this:

  public static void main(String[] argv)
  {
    DateValueGraphPanel dvg_panel = new DateValueGraphPanel(argv[0]);
    Frame f = new Frame();
    f.setLayout(new BorderLayout());
    f.addWindowListener(dvg_panel);
    f.add(dvg_panel);
    f.pack();
    f.show();
  }

"DateValueGraphPanel" has an instance variable for an object of class "GraphCanvas" that extends "Canvas". This GraphCanvas object should be inserted into a ScrollPane, which handles the case where the graph is too big.

The class "DateValueGraphPanel" should contain a public constructor and method implementations for the "WindowListener" interface. "GraphCanvas" could contain the following public methods:

public GraphCanvas(String fname)	// Constructor with date/value file name.
public void paint(Graphics g)		// Paints the graph and a rectangle.
public Dimension getPreferredSize()	// So that ScrollPane lays it out as we want.

Hints:

To be returned: