I'm working on my first project in Processing which is a calculator. I've reached a speed bump. The way I thought I could do digit entry isn't working. Anybody got any ideas?
//All of the below values allow me to quickly change values code wide
final int topRowYPos = 80;
final int secondRowYPos = 110;
final int thirdRowYPos = 140;
final int fourthRowYPos = 170;
final int fithRowYPos = 200;
final int sixthRowYPos = 230;
final int buttonWidth = 35;
final int buttonHeight = 25;
final int firstRowXPos = 45;
final int secondRowXPos = 85;
final int thirdRowXPos = 125;
final int fourthRowXPos = 165;
final int fithRowXPos = 205;
final int maxB = 27;
boolean wTillUpToRefresh; //Selectes wheather you will refresh automaticly or only on next button push
int digitCount = 0; //Counts digits. Required in the process of adding digits.
PFont sF = createFont("Georgia", 16, true); //Creates font used calculator wide
boolean isDecimal; //Checks wheather I've pressed the decimal buttons. Determines wheather the number needs to be to number*10^1 or number*10^-1
double numOneBuffer = 0; //Stores firstnumber;
double numTwoBuffer = 0; //Stores second number;
int numOn = 1; //Counts which position in the calculating process the user is in. 1 is first number, 2 is function(not needed but there) 3 is second number 4 is answer mode
String functionBuffer = "N"; //Stores which function the calculation is using
String screenBuffer = "0"; //Stores what is currently being displayed on the screen
double answerBuffer = 0; //Stores answer
double numMemory = 0; //Stores one varible in "Memory"
int buttonPressed = -1; //Detects what button has been pressed
boolean sign = true;
Button[] buttons = new Button [maxB]; //Button array for all buttons
void setup() {
size(250, 280);
//The following lines initilize the buttons
buttons[0] = new Button(firstRowXPos, secondRowYPos, "MC", false);
buttons[1] = new Button(firstRowXPos, thirdRowYPos, "%", false);
buttons[2] = new Button(firstRowXPos, fourthRowYPos, "+/-", false);
buttons[3] = new Button(firstRowXPos, fithRowYPos, "C", false);
buttons[4] = new Button(firstRowXPos, sixthRowYPos, "AC", false);
buttons[5] = new Button(secondRowXPos, secondRowYPos, "MR", false);
buttons[6] = new Button(secondRowXPos, thirdRowYPos, "7", false);
buttons[7] = new Button(secondRowXPos, fourthRowYPos, "4", false);
buttons[8] = new Button(secondRowXPos, fithRowYPos, "1", false);
buttons[9] = new Button(secondRowXPos, sixthRowYPos, "0", false);
buttons[10] = new Button(thirdRowXPos, secondRowYPos, "M-", false);
buttons[11] = new Button(thirdRowXPos, thirdRowYPos, "8", false);
buttons[12] = new Button(thirdRowXPos, fourthRowYPos, "5", false);
buttons[13] = new Button(thirdRowXPos, fithRowYPos, "2", false);
buttons[14] = new Button(thirdRowXPos, sixthRowYPos, "=", false);
buttons[15] = new Button(fourthRowXPos, topRowYPos, "√", false);
buttons[16] = new Button(fourthRowXPos, secondRowYPos, "M+", false);
buttons[17] = new Button(fourthRowXPos, thirdRowYPos, "9", false);
buttons[18] = new Button(fourthRowXPos, fourthRowYPos, "6", false);
buttons[19] = new Button(fourthRowXPos, fithRowYPos, "3", false);
buttons[20] = new Button(fourthRowXPos, sixthRowYPos, ".", false);
buttons[21] = new Button(fithRowXPos, topRowYPos, "off", false);
buttons[22] = new Button(fithRowXPos, secondRowYPos, "÷", false);
buttons[23] = new Button(fithRowXPos, thirdRowYPos, "*", false);
buttons[24] = new Button(fithRowXPos, fourthRowYPos, "-", false);
buttons[25] = new Button(fithRowXPos, fithRowYPos, "", true);
buttons[26] = new Button(fithRowXPos, sixthRowYPos, "", true);
I'm making a calculator as a beginning project. Everything has been going fine until I got to programming the buttons. When I tried to implement button hover detection instead of detecting over the button it detected over the screen (number output).
My code is below:
Calculator.pde
import java.text.NumberFormat;
import java.text.DecimalFormat;
PFont f;
final int topRowYPos = 80;
final int secondRowYPos = 110;
final int thirdRowYPos = 140;
final int fourthRowYPos = 170;
final int fithRowYPos = 200;
final int sixthRowYPos = 230;
final int buttonWidth = 35;
final int buttonHeight = 25;
final int firstRowXPos = 45;
final int secondRowXPos = 85;
final int thirdRowXPos = 125;
final int fourthRowXPos = 165;
final int fithRowXPos = 205;
int digitCount;
boolean isDecimal;
double numOneBuffer;
double numTwoBuffer;
double screenBuffer;
double numMemorY;
Button mc = new Button(firstRowXPos, secondRowYPos);
Button percent = new Button(firstRowXPos, thirdRowYPos);
NumberFormat formatter = new DecimalFormat("0.0000000");