Broken, messy code wouldn't fit in the same post...
Quote:
import processing.opengl.*;
import java.lang.reflect.*;
import java.util.ArrayList;
import processing.core.*;
ExampleFrame look;
void setup(){
size(200,200,OPENGL);
look=new ExampleFrame();
look.setVisible(true);
}
void draw(){
line(200,0,0,200);
Object[] par=new Object[2];
par[0]=Integer.TYPE;
par[1]=Integer.TYPE;
//look.up();
//println(look.embed.draw());
println(frameRate);
}
public void drawLine(){
line(50,100,30,400);
}
//can call the update method on any passed object
public void callUpdate(String com,Object[] args){
//we need to build the class[] array for the getMethod
Class[] cls = new Class[0];
Class myC;
for(int t=0;t<args.length;t++){
Class tempC = args[t].getClass();
Field[] typeC = tempC.getFields();
if(typeC.length>0){
Field myType=typeC[typeC.length-1];
myC = myType.getType();
println(myType.getName());
cls = (Class[]) append(cls,tempC);
println(myType);
}
}
//Class[] cls = {Float.TYPE,Float.TYPE,Float.TYPE,Float.TYPE};
Class go = this.getClass();
Method me;
try{
me = go.getMethod(com,cls);
me.invoke(this,args);
}catch(Exception e){
e.printStackTrace();
}
}
public class ExampleFrame extends Frame {
PApplet embed;
public ExampleFrame() {
super("Embedded PApplet");
setSize(400,400);
setLayout(new BorderLayout());
embed = new Embedded();
add(embed, BorderLayout.CENTER);
// important to call this whenever embedding a PApplet.
// It ensures that the animation thread is started and
// that other internal variables are properly set.
embed.init();
}
}
public class Embedded extends PApplet{
public void setup() {
// original setup code here ...
size(400, 400,OPENGL);
frameRate(30);
// prevent thread from starving everything else
//noLoop();
}
public void draw() {
// drawing code goes here
float x= 10.0;
float y=100.0;
float x1=50.0;
float y1=400.0;
Object[] pars = {new Float(10.0),new Float(100.0),new Float(50.0),new Float(400.0)};
callUpdate("line",pars);
line(0,0,400,400);
println("Embed:"+frameRate);
}
/*
*/
public void mousePressed() {
// do something based on mouse movement
// update the screen (run draw once)
redraw();
}
}