Date: Thu, 03 Oct 2002 2:35 p.m. From: Mark Jacobson To: 810-061-01@uni.edu, 810-061-02@uni.edu Subject: this.canvas = canvas; Hi Java 061 students, The following statement is needed in your Die constructor, to set the PIV (Private Instance Variable) for the Die that is being constructed so it "remembers" what window or canvas or DrawingCanvas object that this particular dice is on. ------------- this.canvas = canvas; The formal parameter name is canvas, as you can see here in the Die constructor header: ------ public Die (double xCoord, double yCoord, DrawingCanvas canvas) { -------------------- The canvas here for the constructor's 3rd parameter is a LOCAL VARIABLE, but one that can receive information from the outside world, i.e. from the Yahtzee client program that needs to have Die objects constructed and needs to use Die objects. Your PIV (Private Instance Variable) is identically named canvas. ----------- private DrawingCanvas canvas; This PIV, since it has the SAME NAME as the parameter, needs to be prefixed with the word this, to refer to the Die object's private instance variable, the Die object's PIV. Thus the statement you add to the contructor is: this.canvas = canvas; PIV canvas = parameter canvas INSTANCE = LOCAL PARAMETER VARIABLE of VARIABLE the Die constructor method this.canvas = canvas; Be sure to reread the pages of the Williams textbook about the this Java keyword. You could avoid using this in a statement like this.canvas = canvas; if you had a different name for the Formal Parameter, say for example, theCanvas, instead of canvas. --------- ------ public Die (double xValue, double yValue, DrawingCanvas theCanvas) { --------- UNIQUE canvas = theCanvas; NAME, different ------ --------- from the PIV PIV = Formal Parameter variable name... Of course you would still be welcome to say: this.canvas = theCanvas; but this would not be required. ---- } Hope you understand all of this stuff. ---- Good luck with your Yahtzee game. Oh yes, one more thing. Compiling the Yahtzee.java file is necessary, and that INDIRECTLY compiles the Die.java file each time. You cannot compile the Die.java file by itself, without getting errors. Mark