// Practice: class button Button b1, b2, b3, b4; //Declares the instances or objects of the class Button. void setup() { size(800, 600); b1= new Button( "Adam", 100, 100, 200, 155, 200); //Defines the instances of the class Button. Variables take the place b2= new Button( "Steve", 200, 100, 255, 50, 100); //of the dummy variables entered in the cosntructors. b3= new Button( "Carl", 300, 100, 50, 100, 255); b4= new Button( "Cancer", 400, 100, 150, 255, 100); } void draw() { b1.show(); b2.show(); b3.show(); b4.show(); } //Events void mousePressed() { background(255); if(b1.clicked( mouseX, mouseY)) { background(0); } if(b2.clicked( mouseX, mouseY)) { background(0); } if(b3.clicked( mouseX, mouseY)) { background(0); } if(b4.clicked( mouseX, mouseY)) { background(0); } } class Button { float x,y; float w=80, h=30; String s; int r,g,b; boolean action; //Constructors Button( String s, float x, float y) //Bread and butter constructor with size and text dummy variables. { this.s= s; this.x= x; this.y= y; } Button( String s, float x, float y, int r, int g, int b) //This Constructor allows you to enter color values. See button instantiation. { this.s= s; this.x= x; this.y= y; this.r= r; this.g= g; this.b= b; } void show() //Method to configure everything that will get displayed. Keeps the draw method clean. { fill(r,g,b); strokeWeight(3); rectMode(CORNER); rect( x,y, w, h, 100); //The last parameter is the one that rounds the edges of buttons. strokeWeight(1); //Strokeweight for text?? fill(0); //Text color text( s, x+10, y+20 ); //Centers the text. S is the text entered w the instance. } boolean clicked( float xx, float yy) { background(0); if(xx > x && xx < x+w && yy > y && yy < y+h) { return true; } else return false; } }