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 › Text input into code
Page Index Toggle Pages: 1
Text input into code (Read 640 times)
Text input into code
Nov 7th, 2006, 2:06pm
 
Hi,  

I am starting out in processing, but have a few weeks experience behind me now. I am planning to create a series of programs that will help teach simple architecture in processing. I need however to find a way to input text into the applet, and then use that input text to change parameters such as:

User enters x and y co-ords, width and height
Processing outputs square with co-ords x and y and width and height specified.

I have played around with the 'interfascia' library and I'm sure this could be useful but any pointers would be much appreciated.

Re: Text input into code
Reply #1 - Nov 8th, 2006, 1:16am
 
For simple input, you could use class JOptionPane of the Java library, http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html

Code:

import javax.swing.JOptionPane;

float x;
float y;
float w;
float h;

void setup() {
String input = JOptionPane.showInputDialog("Enter x, y, width and height, separated by spaces");
String[] args = split(input);
x = float(args[0]);
y = float(args[1]);
w = float(args[2]);
h = float(args[3]);
size(200,200);
}
void draw() {
background(0);
rect(x, y, w, h);
}

/Rick
Re: Text input into code
Reply #2 - Nov 8th, 2006, 2:38am
 
Many thanks Rick, exactly the piece of code i needed and so simple! Already playing around with many possibilities.

Again many thanks

James
Page Index Toggle Pages: 1