如何创建在处理单个草图的多个窗口? [英] How to create more than one window of a single sketch in Processing?

查看:284
本文介绍了如何创建在处理单个草图的多个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在加工只用一个单一草图创建两个窗口。

I want to create two windows by using just one single sketch in Processing.

我想要做的是,如果我在一个窗口中点击一个按钮,然后一些形象出现在另一个窗口。

What I'm trying to do is that if I click a button in one window, then some image appear in another window.

我搜索谷歌和发现了一些例子。其实,我发现在这个堆栈溢出网络同样的问题。这里是链接。

I've searched Google and found some examples. Actually, I found the same question in this 'stack overflow web'. Here are the links.

<一个href=\"http://stackoverflow.com/questions/20730901/create-more-than-one-window-of-a-single-sketch-in-processing\">Create在处理单个草图的多个窗口
http://forum.processing.org/one/topic /multiple-windows-2-4-2011.html

Create more than one window of a single sketch in Processing http://forum.processing.org/one/topic/multiple-windows-2-4-2011.html

下面是第二个环节codeS。

Here is the codes of second links.

import java.awt.Frame;
PFrame f;
secondApplet s;
//f = new PFrame();
void setup() {
 size(320, 240);
 f = new PFrame();
}

void draw() {
  background(255,0,0);
   fill(255);
   rect(10,10,frameCount%0,10);
   s.background(0, 0, 255);
   s.fill(100);
   s.rect(10,20,frameCount%0,10);
   s.redraw();
}

public class PFrame extends Frame{
    public PFrame() {
        setBounds(100,100,400,300);
        s = new secondApplet();
        add(s);
        s.init();
        show();
    }
}

public class secondApplet extends PApplet {
    public void setup() {
        size(400, 300);
        noLoop();
    }

    public void draw() {
    }
} 

但是,当我运行这个codeS,我得到了以下错误消息 添加(S)

But when I run this codes, I get the following error message at add(s);.

在类型容器中的方法添加(组件)不适用于参数(multi_window_test.secondApplet)

The method add(Component) in the type Container is not applicable for the arguments (multi_window_test.secondApplet)

$ C $第一环节的第一个评论的c是相似的,但是当我运行此code,我得到同样的错误信息。

Code of first comment of first link is similar, but when I run this code, I get the same error message.

其他例如codeS,我发现都是相似的。他们都创造PFRAME类secondApplet延伸PApplet。他们说,这些codeS效果很好,但我不能运行这些codeS。

Other example codes that I found are all similar. They all create PFrame class and secondApplet which extends PApplet. They said these codes works well but I can't run these codes.

我找不到我的错误消息的原因。其他人似乎都没有问题运行这个例子code,除了我的时候。
如果有人知道的解决方案,请帮助我。

I couldn't find the reason of my error message. Other people seems to have no problem when running this example code except me. If someone knows the solution, please help me.

此外,如果有其他简单的方法在一个草图创建多窗口,请让我知道。

Also, if there is a other simple way to create multi-windows in one sketch, please let me know.

推荐答案

的原因错误消息是pretty言自明:在添加()功能期待一个组件 PApplet 不是组件 。这是因为 PApplet 不再延长 Applet的加工3,这么老code,使用它作为一个的组件将不再工作。

The reason for the error message is pretty self-explanatory: the add() function is expecting a Component, and PApplet is not a Component. This is because PApplet no longer extends Applet as of Processing 3, so old code that uses it as a Component will no longer work.

相反,考虑我的回答这个问题。基本上,只要创建一个扩展 PApplet 你的第二个窗口,一类,然后调用 PApplet.runSketch()使用第二个 PApplet 作为参数:

Instead, consider my answer to this question. Basically, just create a class that extends PApplet for your second window, and then call PApplet.runSketch() using that second PApplet as a parameter:

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);
  }
}

这篇关于如何创建在处理单个草图的多个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆