I need tips about num input:)

HI! I need to get a number input, but it’s all mixed up. I’ve tried
Keypressed - that doesn’t work well because it notices spacebar as input too
and
using virtual buttons like a calculator - that works well but is inconvenient.

Well, I googled it but I couldn’t find out how to get an input just like C.(It appears that there is no such function acting the same way as scanf?)
If anybody has some tips or ideas about getting number inputs in an IntList form, please help me by sharing it.
Thank you.

1 Like

and the JOptionPane ( i showed you already )
also not usable ( just to get you started )
Someone with a bit of free time please help me with receiving int data as IntList ?

( it is functioning code and i expected that you test and comment )


now while button on screen take space they allow well to show each number…
and not forget, that also could be just a first screen for data input,
while your graph would be a second screen ( after press a button called “PLOT” … )

2 Likes

Oh! sorry I didn’t understand the code last time but now I get it clearly. Thanks for Ur help!

Umm, sorry to bother you again. I don’t know even a bit about JAVA, so may I please ask you to teach me how to convert this code in order to get a String?
Thank you.

oh,
well the JOptionPane is a text input
so read it up…
and use it in a pure form ( like for your title input… )

i understood you have trouble to make a NUMBER input,
and to make that safe from text i made for me that 2 functions…

think you might need the askI() only?


now anyhow the first point after testing that function i made around
that pop up window type of input
is that you ask yourself if that is usable in your project,
i can tell you that i not like it too much, as the input window here
( using windows / and processing 3.5.3 / java 8 )
tends to be hidden behind the canvas window
( ok, [ALT][TAB] works ? even on fullscreen? )

2 Likes

Yeah, I needed a int thing and I thank you for the char-preventing part. it is really useful.
Real thanks, but I also need a part for my title… I think I’m asking you too much and maybe bothering you, sorry. But can you just tell me how to change I = Integer.parseInt(r);part into string? I tried I = String.parsechar(r);but I’m not sure about it, and String.parsestring doesn’t even exist.
Again, thank you for your kind reply.


P.s, It pops up perfectly in my computer…? I never experienced it.

please not use the functions and convert back to text,

just learn the
JOptionPane
to get your title…
did you find links about it?

1 Like

Oh! okay, thanks. I never tried Java but I will search about it.
Thanks!

HaHa, I found it like, in like a second! Thank you!

2 Likes

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…

1 Like

Wow! Maybe do you want to see what I did with your code?

int askI(String ask, int I) {
  String r = JOptionPane.showInputDialog(null, "Please enter your values for the graph. "+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;
}

int askN(String ask, int I) {
  String r = JOptionPane.showInputDialog(null, "Please enter the number of data you want for your graph.", "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;
}
void setup(){
  background(0);
  size(2000, 4000);
  textSize(30);
  arr = new IntList();
  //title = 
  title = JOptionPane.showInputDialog("Please enter a title for your graph.");
    num = a = askN("", a);
  for(int i = 0; i < num; i++){
    a = askI("put a value under 10, one at a time.", a);
    arr.append(a);
  }
}
void draw(){}

I use IntList, so I made it like this. Thank you for your help!

2 Likes