# Getting User input

**URL:** <https://discourse.processing.org/t/getting-user-input/1670>\
**Category:** Coding Questions\
**Created:** [July 10, 2018, 10:54pm UTC](https://discourse.processing.org/t/getting-user-input/1670 "2018-07-10T22:54:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 10, 2018, 10:54pm UTC](https://discourse.processing.org/t/getting-user-input/1670/1 "2018-07-10T22:54:23Z")

</div>

Java Proccessing  
OK, I’ve watched several youtube shows of getting the user’s input. Even though I didn’t like the way they did it I tried it since I have no other idea of how to do it. So in the game I’m making my high Score board & want the user’s name. The tutorials I’ve seen shows use Scanner but when I try it & type in my name nothing happens. Here the code.

```auto
import java.util.Scanner;

void setup(){
  size(300,300);
}

void draw(){
  Scanner in = new Scanner(System.in);
  System.out.print("Please enter your name ");
  String name = in.nextLine();
  System.out.println("Hello " +name + "Welcome to Java.");
}

```

Can anyone tell me why I’m not seeing my name after I type it?

---

<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:** [July 10, 2018, 10:57pm UTC](https://discourse.processing.org/t/getting-user-input/1670/2 "2018-07-10T22:57:53Z")

</div>

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

> **[JavasScript's alert(), confirm(), prompt(), isNaN(), isFinite() and some few...](https://Gist.GitHub.com/GoToLoop/8017bc38b8c8e0a5b70b)**
>
> JavasScript's alert(), confirm(), prompt(), isNaN(), isFinite() and some few others as a Java class! - NoRepeatIdInput.pde

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 10, 2018, 11:09pm UTC](https://discourse.processing.org/t/getting-user-input/1670/3 "2018-07-10T23:09:44Z")

</div>

Where are you asking for them to type in all that?

---

<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:** [July 10, 2018, 11:14pm UTC](https://discourse.processing.org/t/getting-user-input/1670/4 "2018-07-10T23:14:55Z")

</div>

By invoking the methods from the class library. 🕶

- [https://Forum.Processing.org/two/discussion/13175/do-whille-is-not-working-how-it-suppose-to](https://Forum.Processing.org/two/discussion/13175/do-whille-is-not-working-how-it-suppose-to)

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 10, 2018, 11:25pm UTC](https://discourse.processing.org/t/getting-user-input/1670/5 "2018-07-10T23:25:39Z")

</div>

I’ve tried Scanner.  
I’ve tried import iadt.creative.Inputs;  
both not working.  
There must be a simple way to do this.  
Can you explain it instead of dropping files .I’ve looked at them tried copying to get what I want and still only errors.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [July 10, 2018, 11:37pm UTC](https://discourse.processing.org/t/getting-user-input/1670/6 "2018-07-10T23:37:49Z")

</div>

@GoToLoop **Please** include explanations when you post links.

---

<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:** [July 11, 2018, 12:00am UTC](https://discourse.processing.org/t/getting-user-input/1670/7 "2018-07-11T00:00:34Z")

</div>

- The gists are presented as 2 files: 1 is a “.pde” & the other is a “.java” file.
- The “.pde” goes to the 1st main tab.
- The 2nd “.java” 1 needs to be created.
- For example, “Inputs.java” contents should go to a tab named exactly “Inputs.java”.

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 11, 2018, 1:04am UTC](https://discourse.processing.org/t/getting-user-input/1670/8 "2018-07-11T01:04:13Z")

</div>

I got a bunch of errors. I just wasted a day looking for a way to get input from a user I just run into error after error.

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 11, 2018, 5:21am UTC](https://discourse.processing.org/t/getting-user-input/1670/9 "2018-07-11T05:21:31Z")

</div>

Here you can see an example suing the scanner: [http://happycoding.io/examples/java/hello-world/higher-lower-random-computer-player](http://happycoding.io/examples/java/hello-world/higher-lower-random-computer-player)

However, if you are using processing, key events would be handled by your sketch. So, with this in mind, you can do something like this (It will only work after the sketch gains focus aka. you need to click on the sketch before you start taping)

Kf

```java

final String INIT_MSG="Start typing";
String msg=INIT_MSG;

void setup() {
  size(600, 400);
  
}

void draw() {
  background(0);
  fill(255);
  text(msg, 100, 100);
  
  fill(0,250,0);
  text("Mouse click to reset message", 100, height*0.8);
}

void mousePressed() {
  msg=INIT_MSG; //Reset message, prepare for a new message
}

void keyPressed() {

  //Prepare when writing a new message. Next resets message container
  if (msg.equals(INIT_MSG)) {
    msg="";
  }

//Detects only alphanumeric chars
  if ( (key>='a' && key<='z') ||
    (key>='a' && key<='z') ||
    (key>='0' && key<='9') 
    ) {
    msg+=key;
  }
}

```

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [July 11, 2018, 9:16am UTC](https://discourse.processing.org/t/getting-user-input/1670/10 "2018-07-11T09:16:49Z")

</div>

Simplest way is to use G4P GUI builder Tool and it’s library.

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 11, 2018, 1:49pm UTC](https://discourse.processing.org/t/getting-user-input/1670/11 "2018-07-11T13:49:18Z")

</div>

ty ty ty you are a life saver. I can add this

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 11, 2018, 1:50pm UTC](https://discourse.processing.org/t/getting-user-input/1670/12 "2018-07-11T13:50:39Z")

</div>

I looked into GUI JTEXTFolder or something like that & tried it & ran into errors when trying to import the library they said import

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 11, 2018, 2:33pm UTC](https://discourse.processing.org/t/getting-user-input/1670/13 "2018-07-11T14:33:14Z")

</div>

You need to make sure you add the jars to your sketch. The best thing to do is for you to provide your link for this library and tell us how you are managing your jars. If you use a Processing library like G4P or ContolP5, you can install any of them through the contribution manager. They come with examples to get you started. JOptionPane is another option, which comes with Java. You can check for previous examples in the older forum.

Kf

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 11, 2018, 2:51pm UTC](https://discourse.processing.org/t/getting-user-input/1670/14 "2018-07-11T14:51:22Z")

</div>

TY, I’m happy with the current way but I’ll look back into it. btw what are jars?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 11, 2018, 3:02pm UTC](https://discourse.processing.org/t/getting-user-input/1670/15 "2018-07-11T15:02:47Z")

</div>

What is your current way?

Jars are library’s byte code ready to be used in your code. For example, Processing libs are found in the `core.jar` which is part of the Processing distribution, right when you download Processing from the website. For non-Processing libraries, you need to make sure those libraries are accessible by your code. If you build your own code, you will use the `classpath` flag. If you are using Processing to run your code, then you need to include the jar in your sketch. The easiest way is to drag and drop the jar right into the Processing editor. This will create a folder called `code` at the same level as your `data` folder. This `code` folder will contain the jar file(s) and they will be including during the building process for you. To access those function, you need to explicitly make those resources available via `import` statements, for instance `import com.some.external.library`.

You might find this next useful: [http://happycoding.io/tutorials/processing/libraries](http://happycoding.io/tutorials/processing/libraries)

Kf

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [July 11, 2018, 3:36pm UTC](https://discourse.processing.org/t/getting-user-input/1670/16 "2018-07-11T15:36:22Z")

</div>

TY, I’ll try later. This was very useful. Why ain’t all the libraries already able to access?

---

<div class="post-metadata">

**Author:** ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)\
**Post date:** [September 6, 2019, 12:46pm UTC](https://discourse.processing.org/t/getting-user-input/1670/18 "2019-09-06T12:46:42Z")

</div>

`java.util.Scanner` doesn’t work in the Processing IDE. You have to use eclipse or a terminal.
