[EMAIL PROTECTED] wrote:
Jim- right on and well said-  that was exactly my confusion....

Kirillcool said:
you're using core view classes in your model. The Shape and its derived classes 
are for painting on the screen. Although they might seem like a good option to 
use in the model, they aren't in most cases (as you're starting to see), since 
they're targeting the screen (view).

Well Rectangle keeps state in just the way you say it shouldn't, if you mean by 
state enough information to draw it to the screen in a specific place. It has 
an x and a y and you can mutate those through it's methods and as a result of 
that mutation it will draw itself elsewhere. That's state. .

I never said that Rectangle does not keep state.  It does keep state.
Nearly all Shape objects keep state and provide methods for you to
modify that state in various ways (whatever was deemed useful for that
Shape).

What I said is that you cannot use the return value of the getBounds()
method to manipulate the state of a Shape object, even if the original
object was a Rectangle.  You can modify the location of a Rectangle by
calling the setLocation() method on *that* Rectangle object, but you
cannot modify its location by calling the setLocation() on the object
that is returned from its getBounds() method - just like any other Shape.

The return value of Rectangle.getBounds() may be an instance of the
Rectangle class, but it is a new instance that is not the same instance
as the original.  It stores the same x,y,w,h as the original, but it is
a brand new object completely isolated from the original.

For example:

    Rectangle r = new Rectangle(0, 0, 10, 10);
    // the following statement modifies r directly
    r.setLocation(5, 5);
    // setLocation was called on "r" directly
    // r now is located at 5,5

as compared to:

    Rectangle r = new Rectangle(0, 0, 10, 10);
    // the following statement modifies a temporary object
    // which is then dropped on the floor
    r.getBounds().setLocation(5, 5);
    // setLocation was called on the return value of setBounds()
    // *not* on "r" directly
    // r is still located at 0,0

as compared to:

       Shape s = // some shape
       // the following statement modifies a temporary object
       // which is then dropped on the floor
       s.getBounds().setLocation(5, 5);
       // original s is unaffected just like r in previous example

Does that clear things up?

                               ...jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to