[英]Is it possible to draw a rectangle from inside a java class in processing?
我想要一个java对象,我将从main draw()方法中调用object.draw(),这样每次处理草图绘制它时都会绘制java对象。
Yes. 是。
You just need to pass the PApplet
instance into the Java class, and then use that to do your drawing. 您只需将PApplet
实例传递给Java类,然后使用它来进行绘制。
public class MyShape{
PApplet papplet;
public MyShape(PApplet papplet){
this.papplet = papplet;
}
public void draw(){
papplet.ellipse(50, 50, 25, 25);
}
}
And then in your sketch, you would use the this
keyword to pass the sketch into your object: 然后在草图中,您将使用this
关键字将草图传递到对象中:
MyShape myShape;
void setup(){
myShape = new myShape(this);
}
void draw(){
myShape.draw();
}
More info can be found in the reference . 更多信息可以在参考资料中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.