Assignment 12 - Due In Lab April 22-23 on a floppy disk and in print.

List Manager with AWT - Help

I have received many messages from students who find it difficult to conceptualize the way the paint method gets invoked and works. I would like to refer you to Lecture Notes 14 for a description. In what follows I will try to give some help with having a working paint() method that produces almost the expected results.

Start from Lecture Notes 25 (or lab notes from last week).

Work with class AWTExample2.

Add a call to

at the end of actionPerformed(), and the following method as an instance method:
public void paint(Graphics g) {
  if (myList == null) {
    g.drawString("Please start by pressing New", 30, 100); 
  } else if (myList.first == null) {
    g.drawString("Your list is empty.", 30, 100); 
  } else {
    g.drawString(, 30, 100); 
This will essentially bring your output into the Frame.

You will still be displaying a String, but at least you will be doing it through your paint() method. Now all you need to do is to define a show function that draws squares and arrows, instead of returning a String.

You will need to pass the graphics context to that method, otherwise it will not know where to draw.

As a final comment please remember that you never invoke paint() directly.

It will be called for you in the right context.

All you can do is to provide a definition for it, a definition that has a placeholder (the graphics context that is its formal parameter) in it, and which will be filled in appropriately upon its invocation.

The most you can do is to indirectly request that paint() be invoked, and we do this through repaint(). You will note that we inherit this method from Frame or one of its superclasses (from class Component to be more precise).

Note that the purpose of paint() is that of giving the user a picture of the current situation. It is completely separate from any actions on the OneWayList that the user is working with.

Changes to the list are performed by actionPerformed(), which calls repaint(), and that in turn erases the drawable area and then asks paint() to paint the current status again.