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 › Real Time Code Editing
Page Index Toggle Pages: 1
Real Time Code Editing (Read 902 times)
Real Time Code Editing
Nov 21st, 2006, 1:43pm
 
Hi, I'm looking to create a learning application for Processing wherein the user can see and edit at least certain parts of the code to see an affect on the applet. I have already implemented this idea using input boxes and sliders but was wondering if anyone knew of a way of allowing the code to sit - in real time - next to the applet and upon being changed would refresh and redraw?

Any comments/ideas/suggestions much appreciated

J
Re: Real Time Code Editing
Reply #1 - Nov 21st, 2006, 2:46pm
 
see this thread about live code:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1120340727;start=32#32

best,
F
Re: Real Time Code Editing
Reply #2 - Nov 21st, 2006, 5:57pm
 
I've been having a play with something called Janino which is a pure java, java compiler, which will let you compile java from within other code.

However, it's not very nice, so is probably fairly useless for most needs.

Just in case someone's actually interested in seeing how:
Code:
import org.codehaus.janino.*;
import java.lang.reflect.*;

Object a;
String code="import processing.core.*; public class Foo { PApplet p; public Foo(PApplet _p) { p=_p; } public void doodle() { p.g.rect(p.random(0,p.g.width),p.random(0,p.g.height),5,5); } }";

void setup()
{
size(200,200);
try
{
Scanner scanner = new Scanner(null, new StringReader(code));
ClassLoader CL = getClass().getClassLoader();
SimpleCompiler compiler = new SimpleCompiler(scanner, CL);
ClassLoader loader = compiler.getClassLoader();
Class theclass = loader.loadClass("Foo");
Constructor[] c=theclass.getConstructors();
a=c[0].newInstance(new Object[]{this});
}
catch(Exception e)
{
println(e);
}
}

void draw()
{
try
{
a.getClass().getMethod("doodle",null).invoke(a,null);
}
catch(Exception e)
{
println(e);
}
}


Edit: You'll need to get the janino.jar and put it in the code folder for it to work of course...
Page Index Toggle Pages: 1