处理中的新窗口 [英] New window in Processing

查看:118
本文介绍了处理中的新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我在处理"中找到了以下用于创建第二个窗口的代码

Yesterday I found the following code for creating a second window in Processing

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以来,出现了以下错误:

It worked lovely, but since I downloaded and installed Processing III, I've got the following errors:

  • 函数add()需要像add(component)这样的参数.
  • 功能init()不存在.
  • 不赞成使用类型窗口中的方法show().
  • The function add() expects parameters like add(component).
  • The function init() does not exist.
  • The method show() from the type window is deprecated.

推荐答案

首先,该代码不是很好.我很惊讶它在处理2中有效,更不用说处理3了.要非常警惕您只是在Internet上随机找到的代码.

First of all, that code is not very good. I'm surprised it worked in Processing 2, let alone Processing 3. Be very wary of code you just find randomly on the internet.

话虽如此,下面是一些代码:

That being said, here's some code:

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

上面的方法对我有用,尽管这种方法似乎有些骇人听闻.如果您确实希望在草图中有两个窗口,那么最好创建一个生成两个草图的Java应用程序.

The above works for me, although the approach seems pretty hackish. If you really want to have two windows in your sketch, you might be better off creating a Java application that spawns two sketches.

这篇关于处理中的新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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