/************************************************************* * Class for representing a "push bar" (a "button" that runs the * width of the applet). It looks general, but works best near the * top of the Eight_Puzzle applet, and uses some of its global * variables (game, s) and methods (bottomTextMessage()). *************************************************************/ public class PushBar { //"Height" of the bar: private int barHeight; //Its y position: private int positionY; //Fonts: //bigButtonFont is the normal font. //littleButtonFont is what shows when the button is pressed. private PFont bigButtonFont, littleButtonFont; /************************************************************* * Constructor's first parameter is the bar's height, the second * its position. *************************************************************/ public PushBar(int barHeight, int positionY) { this.barHeight = barHeight; this.positionY = positionY; //The background behind the bar: fill(0); rect(0, positionY, width, barHeight); //The bar itself: noStroke(); fill(200, 226, 120); rect(0, positionY, width - 1, barHeight); stroke(0); littleButtonFont = loadFont("Skia-Regular_Regular-13.vlw"); bigButtonFont = loadFont("Skia-Regular_Regular-14.vlw"); //Text label in the bar: textFont(bigButtonFont, 14); fill(0); text("Click here to restart", 40, positionY + barHeight - 5); } /************************************************************* * Invoke when the bar should be pressed (when the mouse is * pressed and the mouse is over the bar). *************************************************************/ public void press () { if (mouseOver()) { //The background behind the bar: fill(0); rect(0, positionY, width, barHeight); //The bar itself (smaller when pressed): noStroke(); fill(190, 200, 110); rect(2, positionY + 2, width - 4, barHeight - 3); stroke(0); //Text label on the bar (also smaller when pressed): textFont(littleButtonFont, 12); fill(0); text("Click here to restart", 45, positionY + barHeight/2 + 5); reset(); } } /************************************************************* * Invoke when the bar should be release (when the mouse is * released and the mouse is over the bar). *************************************************************/ public void release () { if (mouseOver()) { //The background behind the bar: fill(0); rect(0, positionY, width, barHeight); //The bar itself: noStroke(); fill(200, 226, 120); rect(0, positionY, width - 1, barHeight); stroke(0); //Text label on the bar: textFont(bigButtonFont, 14); fill(0); text("Click here to restart", 40, positionY + barHeight/2 + 5); } } /************************************************************* * Returns true when the mouse is over the bar. *************************************************************/ public boolean mouseOver () { return (positionY <= mouseY && mouseY <= barHeight - 2); } /****************************************************** * Put everything back the way it was at the beginning. ******************************************************/ private void reset () { game = new EightPuzzle(); //MODIFY: Invoke the reset() method for each Square //in the array s. //MODIFY: bottomTextMessage("Put appropriate message here.", 5); } }