still i recommend to somehow see what you are typing,
- minimal a prinln(str_n)
- better text(str_n,x,y); @TfGuy44 example
- JOptionPane is a real editable text input in a extra little window what often hides behind main window
- G4P textField is the best ( as it shows up in the canvas )
takes [ctrl][c] / [ctrl][v] .select…cursor move…
( but not select [ctrl] ??? )
for play that little input window after a button press and check for number ( float / int )
import javax.swing.JOptionPane;
int N = 0, Y = 69;
float A, B, C, D = 0.0;
color B_border = color(255); // white
color B_fillG = color(0, 255, 0); // green
color B_fillB = color(0, 0, 255); // blue
color B_fillY = color(255, 255, 0); // yellow
color B_text = color(255, 0, 0); // red
int B_textsize=15;
//_________________________________________________________________ Button Menu
void show_Parameter_Buttonmenu() {
textAlign(CENTER);
textSize(15);
strokeWeight(1);
stroke(255); // white
line(480, 0, 480, 384); // for button area
//show_button(int xpos, int ypos, int xwide, int ywide, String Btxt, color border, color filler, color texter)
show_button(485, 5, 73, 20, "A:"+A, B_border, B_fillG, B_text );
show_button(485, 30, 73, 20, "B:"+B, B_border, B_fillG, B_text );
show_button(485, 55, 73, 20, "C:"+C, B_border, B_fillG, B_text );
show_button(485, 80, 73, 20, "D:"+D, B_border, B_fillG, B_text );
show_button(485, 105, 73, 20, "N:"+N, B_border, B_fillB, B_text );
show_button(485, 130, 73, Y, "dY:"+Y, B_border, B_fillY, B_text );
}
//_________________________________________________________________ SETUP
void setup() {
size(562, 340);
}
//_________________________________________________________________ DRAW
void draw() {
background(200);
ambient(80); //lights(); // static settings
textAlign(LEFT);
textSize(20);
text("Z = "+A+" + "+B+" * X + "+C+" * XX + "+D+" * XXX ", 20, 25); // float
text("N = "+N, 20, 45); // int
show_Parameter_Buttonmenu();
}
//_________________________________________________________________ diag print only
void mouseReleased() {
if (mouseButton == LEFT) {
print("LEFT: ");
if (overRect(485, 5, 73, 20)) A = askF("A", A);
if (overRect(485, 30, 73, 20)) B = askF("B", B);
if (overRect(485, 55, 73, 20)) C = askF("C", C);
if (overRect(485, 80, 73, 20)) D = askF("D", D);
if (overRect(485, 105, 73, 20)) N = askI("N", N);
if (overRect(485, 130, 73, Y)) Y = askI("dY", Y);
}
if (mouseButton == RIGHT) {
print("RIGHT: ");
}
if (mouseButton == CENTER) {
print("WHEEL: ");
}
}
// tab common
// for button menu ask setpoint input
//_________________________________________________________________ askI call: A = askI("A",A);
int askI(String ask, int I) {
String r = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+I+" )", "Input (INT)", JOptionPane.QUESTION_MESSAGE);
if (r == null ) {
print(" NULL ");
r = str(I);
} // handle CANCEL
try {
I = Integer.parseInt(r);
}
catch(NumberFormatException e) {
println("you did not enter a int number!");
}
println("new "+ask, I);
return I;
}
//_________________________________________________________________ askF call: A = askF("A",A);
float askF(String ask, float F) {
String r = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+F+" )", "Input (FLOAT)", JOptionPane.QUESTION_MESSAGE);
if (r == null ) {
print(" NULL ");
r = str(F);
} // handle CANCEL
try {
F = Float.parseFloat(r);
}
catch(NumberFormatException e) {
println("you did not enter a int or float number!");
}
println("new "+ask, F);
return F;
}
//_________________________________________________________________ mouse position over rectangle yes/no
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
//_________________________________________________________________ show_button
void show_button(int xpos, int ypos, int xwide, int ywide, String Btxt, color border, color filler, color texter) {
textAlign(CENTER);
textSize(B_textsize);
strokeWeight(2); // Button border width
stroke(border); // Button border color
fill(filler); // Button fill color
rect(xpos, ypos, xwide, ywide); // Button rectangle
fill(texter); // text color
text(Btxt, xpos + xwide/2, ypos+ywide/2+B_textsize/2); // some pix too low
noStroke();
}