有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java运行一个处理类的对象

我在Eclipse中有一个名为“VisualST”的处理类,我创建了一个名为“tree”的VisualST类型的对象。现在我了解到,您可以使用main函数(在类GUI中)中的以下行来运行VisualST类

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

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

我可以在类GUI中单击按钮编辑字段,该类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) 个答案