使用处理库-在处理草图的Java文件中?
在某种程度上是对的一种跟进;使用中的示例,我有以下内容:使用处理库-在处理草图的Java文件中?,java,processing,Java,Processing,在某种程度上是对的一种跟进;使用中的示例,我有以下内容: /tmp/Sketch/Sketch.pde // forum.processing.org/two/discussion/3677/ // usage-class-from-java-file-is-there-a-full-doc-for-that Foo tester; void setup() { size(600, 400, JAVA2D); smooth(4); noLoop(); clear();
/tmp/Sketch/Sketch.pde
// forum.processing.org/two/discussion/3677/
// usage-class-from-java-file-is-there-a-full-doc-for-that
Foo tester;
void setup() {
size(600, 400, JAVA2D);
smooth(4);
noLoop();
clear();
rectMode(Foo.MODE);
fill(#0080FF);
stroke(#FF0000);
strokeWeight(3);
tester = new Foo(this);
tester.drawBox();
}
/tmp/Sketch/Foo.java
import java.io.Serializable;
//import peasy.org.apache.commons.math.geometry.Rotation;
//import peasy.org.apache.commons.math.geometry.Vector3D;
import processing.core.PApplet;
import processing.core.PGraphics;
public class Foo implements Serializable {
static final int GAP = 15;
static final int MODE = PApplet.CORNER;
final PApplet p;
Foo(PApplet pa) {
p = pa;
}
void drawBox() {
p.rect(GAP, GAP, p.width - GAP*2, p.height - GAP*2);
}
}
该示例按原样运行良好-但如果我取消注释import peasy.org…
行,则编译失败,原因是:
The package "peasy" does not exist. You might be missing a library.
Libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder.
当然,我确实在/path/to/processing-2.1.1/modes/java/libraries/PeasyCam/
-下安装了PeasyCam,如果我执行导入peasy.*,它就可以正常工作代码>来自.pde
草图
我想,这与路径有关——显然是草图中的纯Java文件,而不是与草图中的.pde文件引用相同的库路径
有没有可能让这个草图用import peasy.org…
行编译(我想,除了复制/符号链接草图文件夹中的peasycam
库之外,这里是/tmp/sketch/
这是您了解到处理实际上不是Java的地方,它只是有一个类似的(ish)代码)语法,可以通过将所有.pde文件聚合到一个类中在JVM中运行其代码,该类可以编译以在JVM上运行。处理有自己的规则来处理导入等
为什么不完全在处理过程中这样做呢
class Foo {
static int MODE = ...;
static int GAP = ...;
PApplet sketch;
public Foo(PApplet _sketch) {
sketch = _sketch;
...
}
void drawBox() {
sketch.rect(GAP, GAP, p.width - GAP*2, p.height - GAP*2);
}
...
}
然后确保将其保存在一个文件Foo.pde
中或与草图位于同一目录的某个文件中,并通过常规处理导入机制将草图加载到peasy库中?好的,感谢您的回答,特别是“通过将所有.pde文件聚合到一个类中”,在第一次引用foo之前,我只是尝试在.pde文件中导入peasy
;也就是说,在/tmp/Sketch/Sketch.pde中,我现在有:
// forum.processing.org/two/discussion/3677/
// usage-class-from-java-file-is-there-a-full-doc-for-that
import peasy.*; // add this
Foo tester;
...
…然后草图就可以毫无问题地编译了(但请注意:虽然这种方法在本例中有效,但在促使我发布问题的原始问题中却不起作用)。非常感谢,@MikePomaxKamermans-感谢您的回答,我只是在.pde中添加了import peasy.*;
(见下文),现在OP中的示例编译起来没有问题。“为什么不完全在处理过程中执行此操作呢”-因为我想为peasycam
类之一提供一个替代类,该类大部分是它的副本;因此,直接在Java中进行一些更改会更方便。再次感谢-干杯!