# I need tips about num input:)

**URL:** https://discourse.processing.org/t/i-need-tips-about-num-input/15973
**Category:** Beginners
**Created:** [November 30, 2019, 9:17am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973 "2019-11-30T09:17:11Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 9:17am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/1 "2019-11-30T09:17:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 30, 2019, 9:44am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/2 "2019-11-30T09:44:07Z")

</div>

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](https://discourse.processing.org/t/someone-with-a-bit-of-free-time-please-help-me-with-receiving-int-data-as-intlist/15826/6) ?

( 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” … )

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 9:56am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/3 "2019-11-30T09:56:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 10:14am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/4 "2019-11-30T10:14:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 30, 2019, 10:17am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/5 "2019-11-30T10:17:53Z")

</div>

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? )

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 10:24am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/6 "2019-11-30T10:24:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 30, 2019, 10:26am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/7 "2019-11-30T10:26:13Z")

</div>

please not use the functions and convert back to text,

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

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 10:26am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/8 "2019-11-30T10:26:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 10:29am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/9 "2019-11-30T10:29:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [November 30, 2019, 10:30am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/10 "2019-11-30T10:30:16Z")

</div>

> <https://gist.github.com/GoToLoop/bba0c288aaeeb5ef9bb1>

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 30, 2019, 10:36am UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/11 "2019-11-30T10:36:18Z")

</div>

now making a function ( my version ) even has merit for a simple text input:  
( it’s about using the cancel button… )

```auto
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:

```auto
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…

---

<div class="post-metadata">

### Author: ![24stevek](https://avatars.discourse-cdn.com/v4/letter/2/edb3f5/32.png) [@24stevek](https://discourse.processing.org/u/24stevek)
#### Post date: [November 30, 2019, 12:01pm UTC](https://discourse.processing.org/t/i-need-tips-about-num-input/15973/12 "2019-11-30T12:01:55Z")

</div>

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

```auto
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!
