Hi--I'm continuing on my path to learning how to use Clojure with the
graphics library Piccolo2D (http://
www.piccolo2d.org) by re-implementing some of Piccolo2D's sample
programs. This time, I'm working on the "Building the Interface"
program described at http://www.piccolo2d.org/learn/interface.html.

I've used proxy successfully several times so far, but I'm not sure I
can use it here. The code that I'm trying to translate is as follows:

-----------------------------------
class ToggleShape extends PPath {

  private boolean fIsPressed = false;

  public ToggleShape() {
    setPathToEllipse(0, 0, 100, 80);

    addInputEventListener(new PBasicInputEventHandler() {
      public void mousePressed(PInputEvent event) {
        super.mousePressed(event);
        fIsPressed = true;
        repaint();
      }
      public void mouseReleased(PInputEvent event) {
        super.mouseReleased(event);
        fIsPressed = false;
        repaint();
      }
    });
  }

  protected void paint(PPaintContext paintContext) {
    if (fIsPressed) {
      Graphics2D g2 = paintContext.getGraphics();
      g2.setPaint(getPaint());
      g2.fill(getBoundsReference());
    } else {
      super.paint(paintContext);
    }
  }
}
-----------------------------------

Some questions:

1) Because this new class, ToggleShape, has the added state of
fIsPressed, is it possible to use proxy at all, or do I have to use
gen-class? If it's the latter, how do I declare the namespace that
surrounds the gen-class so that this new class is visible to the code
that uses it?

2) If I can use proxy, do I create a constructor for this nameless new
class by redefining PPath (which is, after all, the name of the
constructor for the superclass)?

As always, thanks for your help.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to