我有四个坐标作为全局变量保存在主类中。如何访问 getter 或为新 Applet 提供参数?无法创建实例,因为主类的值是在第二个 Applet 的代码运行之前设置的。 当按下鼠标和释放鼠标时,位置将保存在我的主小程序中。通过释放鼠标按钮,另一个 Java 类中的第二个 Applet 被打开。 目标是第二个 Applet 的大小为鼠标刚刚拖动的矩形。
public void mousePressed() {
setStartDetectionAreaX(mouseX);
setStartDetectionAreaY(mouseY);
}
public void mouseReleased(){
setEndDetectionAreaX(mouseX);
setEndDetectionAreaY(mouseY);
PApplet.main("SecondWindow");
}
最佳答案
好吧,我找到了解决方案。调用其他 Applet 时可以将字符串数组作为参数。 像这样:
PApplet.main("SecondWindow", new String[]{pm1, pm2, pm3, pm4};
在另一个类中,它知道可以像这样获取数组:
args[0]
另一种可能性是设置一个静态变量并在另一个类中更改它。
关于java - 如何使用Processing在Java中的Applet类之间传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61373218/