运行Processing类的对象

时间:2013-02-24 20:18:30

标签: java eclipse processing

我在Eclipse中有一个名为“VisualST”的Processing类,我创建了一个名为VisualST类型的“tree”对象。现在我明白你可以使用main函数中的下面一行来运行VisualST类(在GUI类中)。

PApplet.main(new String[] {"VisualST" });

问题是我将数据存储到VisualST类(因此是对象)中,我需要一种方法来运行特定的VisualST,或者只需运行一个VisualST,在该VisualST中,可以在程序运行时编辑字段。当我刚刚运行PApplet主函数时,我得到了显示的窗口,但无法访问改变窗口构建方式的字段。

我可以在类GUI中单击按钮来编辑字段,这是没有处理导入的Java:

 public class ButtonListener implements ActionListener
{
    public void actionPerformed (ActionEvent e){

        if(isInteger(BInput.getText())) 
            val = Integer.parseInt(BInput.getText());

         tree.setstval(val);//edits tree! a specific VisualST object
        }

    }








以下是VisualST类的要点:

    import processing.core.PApplet;

public class VisualST extends PApplet {

int stbranch;
int lvls;
//the branch class takes PApplet, length, value (that will be display), and rgb
public branch rt;
public int stval;//start value that should be changed when button is pressed


public void setup() {
    size(360, 640);
    stbranch = 120;
    lvls = 5;
}



public void draw() {
    background(150);
    //start at the top of screen and start drawing
    translate(width/2,0);
    //stval is passed through the constructor and then drawn as the value
    rt = new branch(this, stbranch, stval, 0, 0, 0);
    translate(0, stbranch);
    makeBranch(lvls, stbranch*2/3, 0);
}


void makeBranch(int lvls, double stlength, float y)
{
     //this makes the tree
}

        }

这是分支构造函数:

    import processing.core.PApplet;

public class branch {


double y;
public int value;
PApplet parent;

int r;
int g;
int b;

private branch left;
private branch right;
int opacity; //0-255



branch(PApplet p, double fy, int v, int ir, int ig, int ib){
parent = p;
y = fy;
value = v;
opacity = 200;
parent.stroke(ir, ig, ib, opacity);
parent.line(0, 0, 0, (float)y);
parent.noFill();
parent.stroke(ir, ig, ib, opacity);
parent.ellipse(0, (float)(10+y), 20, 20); 
parent.fill(ir, ig, ib, opacity+25);
parent.text(value, -5,(float)(10+5+y));
} 

0 个答案:

没有答案