Code Wed Apr 8 v1
//Incorrect code in the constructor
Button( float x, float y, float w, float h, String label ){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.label = label;
//the problem is that I created new local variables
//rather than initializing the class instance variables
color selectedColor = color( 280, 100, 100); //purple
color defaultColor = color( 280, 80,70);//dull, dark version
color currentColor = defaultColor;
selected = false; //button starts in off state
} //end constructor//Correct code in the constructor
Button( float x, float y, float w, float h, String label ){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.label = label;
//Correct code: remove dataType: color
//so that I'm now setting values for instance variables
selectedColor = color( 280, 100, 100); //purple
defaultColor = color( 280, 80,70);//dull, dark version
currentColor = defaultColor;
selected = false; //button starts in off state
} //end constructorFull Code: Main Tab
Class Button - version 1
Last updated