处理中的新 window
New window in Processing
昨天我在 Processing
中找到了以下用于创建第二个 window 的代码
import javax.swing.JFrame;
PFrame f;
secondApplet s;
void setup() {
size(600, 340);
}
void draw() {
background(255, 0, 0);
fill(255);
}
void mousePressed(){
PFrame f = new PFrame();
}
public class secondApplet extends PApplet {
public void setup() {
size(600, 900);
noLoop();
}
public void draw() {
fill(0);
ellipse(400, 60, 20, 20);
}
}
public class PFrame extends JFrame {
public PFrame() {
setBounds(0, 0, 600, 340);
s = new secondApplet();
add(s);
s.init();
println("birh");
show();
}
}
并编辑...
void mousePressed(){
PFrame f = new PFrame();
}
进入:
if(mousePressed && mouseX > 1050 && mouseX < 1350 && mouseY > 700 && mouseY < > 750) {
f = new PFrame();
}
}
它运行良好,但自从我下载并安装了 Processing III 后,我遇到了以下错误:
- 函数
add()
需要像 add(component)
. 这样的参数
- 函数
init()
不存在。
- 类型 window 中的方法
show()
已弃用。
处理 3 已更改,因此它不再依赖于 AWT 以提供更大的灵活性,但破坏了依赖于它的代码(如 JFrames 等)。新的方法是使用 PSurfaces,但目前缺少文档和示例。 Processing 3 的这一部分正在积极开发中,因此您需要稍等片刻。
首先,那个代码不是很好。我很惊讶它在 Processing 2 中工作,更不用说 Processing 3 了。要非常小心你在 Internet 上随机找到的代码。
话虽如此,这里有一些代码:
void setup() {
size(100, 100);
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
background(0);
ellipse(50, 50, 10, 10);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
上面的方法对我有用,尽管这种方法看起来很老套。如果你真的想在你的草图中有两个 windows,你最好创建一个生成两个草图的 Java 应用程序。
昨天我在 Processing
中找到了以下用于创建第二个 window 的代码import javax.swing.JFrame;
PFrame f;
secondApplet s;
void setup() {
size(600, 340);
}
void draw() {
background(255, 0, 0);
fill(255);
}
void mousePressed(){
PFrame f = new PFrame();
}
public class secondApplet extends PApplet {
public void setup() {
size(600, 900);
noLoop();
}
public void draw() {
fill(0);
ellipse(400, 60, 20, 20);
}
}
public class PFrame extends JFrame {
public PFrame() {
setBounds(0, 0, 600, 340);
s = new secondApplet();
add(s);
s.init();
println("birh");
show();
}
}
并编辑...
void mousePressed(){
PFrame f = new PFrame();
}
进入:
if(mousePressed && mouseX > 1050 && mouseX < 1350 && mouseY > 700 && mouseY < > 750) {
f = new PFrame();
}
}
它运行良好,但自从我下载并安装了 Processing III 后,我遇到了以下错误:
- 函数
add()
需要像add(component)
. 这样的参数
- 函数
init()
不存在。 - 类型 window 中的方法
show()
已弃用。
处理 3 已更改,因此它不再依赖于 AWT 以提供更大的灵活性,但破坏了依赖于它的代码(如 JFrames 等)。新的方法是使用 PSurfaces,但目前缺少文档和示例。 Processing 3 的这一部分正在积极开发中,因此您需要稍等片刻。
首先,那个代码不是很好。我很惊讶它在 Processing 2 中工作,更不用说 Processing 3 了。要非常小心你在 Internet 上随机找到的代码。
话虽如此,这里有一些代码:
void setup() {
size(100, 100);
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
background(0);
ellipse(50, 50, 10, 10);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
上面的方法对我有用,尽管这种方法看起来很老套。如果你真的想在你的草图中有两个 windows,你最好创建一个生成两个草图的 Java 应用程序。