now making a function ( my version ) even has merit for a simple text input:
( it’s about using the cancel button… )
import javax.swing.JOptionPane;
// 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;
}
//_________________________________________________________________ askI call: A = askI("A",A);
String askS(String ask, String s) {
String si = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+s+" )", "Input (TXT)", JOptionPane.QUESTION_MESSAGE);
if (si == null ) {
print(" NULL ");
si = s;
} // handle CANCEL
println("new "+ask, si);
return si;
}
String title="txt";
int a = 0;
float b = PI;
void setup() {
title = askS("input title ",title);
a = askI("input a ", a);
b = askF("input b ", b);
println("title "+title+" a "+a+" b "+b);
}
void draw() {
}
and a version for automated input of your data:
import javax.swing.JOptionPane;
// 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;
}
//_________________________________________________________________ askI call: A = askI("A",A);
String askS(String ask, String s) {
String si = JOptionPane.showInputDialog(null, "new Setpoint for "+ask+" (now "+s+" )", "Input (TXT)", JOptionPane.QUESTION_MESSAGE);
if (si == null ) {
print(" NULL ");
si = s;
} // handle CANCEL
println("new "+ask, si);
return si;
}
String title="txt";
int nums = 0;
int[] vals;
void setup() {
title = askS("input title ",title);
nums = askI("input nums ", nums);
vals = new int[nums];
println("title "+title+" nums "+nums);
for ( int i = 0; i<nums; i++ ) vals[i] = askI(" data ["+i+"] : ",0);
println(vals);
}
void draw() {
}
but i know the popup window thing is not the nicest way…