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.
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?
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.
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
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;
}
}
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.
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.