We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Storing user keyboard input
Page Index Toggle Pages: 1
Storing user keyboard input (Read 388 times)
Storing user keyboard input
Apr 15th, 2008, 7:13pm
 
Hi guys, I'm somewhat new to Java and haven't come across this issue until now. Basically what I need to do is store a series of user inputed integers in separate variables which will be used later in the program. I'm familiar with C++ and doing keyboard input there but it is different in Processing. I'd like to start basic and do it just through the console but eventually I would like to do it on screen. From what I understand so far I will need to use import java.io.*. I found this little snippet of code:

import java.io.*;

public class Class1
{
 public static void main (String[] args)
  {
  BufferedReader keyboard;
  InputStreamReader reader;
      String InputText = "";

  reader  = new InputStreamReader(System.in);
  keyboard  = new BufferedReader(reader);
 

   try
    {
      InputText = keyboard.readLine( );
      System.out.println("you typed: " + InputText);
    }
   catch (IOException e)
    {
      System.out.println("There was an error");
    }

  }
}

But compiling it in Processing I get an error:

java.lang.ClassCastException: Class1
at processing.core.PApplet.main(PApplet.java:6943)


I know that I will need to convert the String to an integer after but I can't even get that far. Does anyone have any idea on how I can do this? Any help would be appreciated.

Thanks
JavaMan
Re: Storing user keyboard input
Reply #1 - Apr 16th, 2008, 10:59am
 
Hi,

I've seen a similar post before, but can't find it. Here is what I would say :

If you want to learn Processing, you shouldn't start with such C/Pascal examples. It was not made for this purpose and won't work with the code you provide, since the syntax of Processing is not the one you use in Java.

See the Learning section and its examples, and if you want more info on how to get/store user input, see the Reference > Language page and/or the GUI libraries on the Reference > Library page.
Re: Storing user keyboard input
Reply #2 - Apr 16th, 2008, 12:10pm
 
perhaps looking at the source for the p5 library text box would help?

http://sojamop5.svn.sourceforge.net/viewvc/sojamop5/trunk/src/controlP5/Textarea.java?revision=108&view=markup
Page Index Toggle Pages: 1