[4522] in java-interest

home help back first fref pref prev next nref lref last post

Embellishment problem -- what am I doning wrong?

daemon@ATHENA.MIT.EDU (Christopher Helck)
Thu Jan 4 19:48:53 1996

Date: Wed, 3 Jan 1996 11:10:22 -0500
From: chris@tkna.com (Christopher Helck)
To: java-interest@java.Eng.Sun.COM

I'm trying to write an embellishment class (ala "Design Patterns") to draw a 
border around a Component. Here is my code:

---------
import java.lang.*;
import java.awt.*;
import java.applet.Applet;

public class Foo extends Applet {
   public void init() {
      setLayout(new BorderLayout());
      add("Center", new Border(new Button("Center")));
   }
}

class Border extends Panel {
   Border(Component c) {
      setLayout(new BorderLayout());
      add("Center", c);
   }

   public void paint(Graphics g) {
      Dimension d = size();
      setForeground(Color.red);
      g.fillRect(0, 0, d.width-1, d.height-1);
   }
}
--------------------------------------

Note: I've hand typed this example in and I may have added some syntax errors,
but the original compiles and runs.

When the applet runs the button "Center" appears and works, the red rectangle
is never drawn. I've added print statements and discovered that Border's paint
method is never called. Why?

Thanks,

C Helck    chris@tkna.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post