不推荐使用Java和Processing 3.0“框架"类,是否有替代方法? [英] Java and Processing 3.0 “frame” class deprecated, is there an alternative?

查看:51
本文介绍了不推荐使用Java和Processing 3.0“框架"类,是否有替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此处理过去曾经有一个框架"类,该类允许某些通用功能.我试图在屏幕上获取PApplet窗口的位置,但没有"frame"类,我似乎无法做到这一点.

so Processing used to have a "frame" class which allowed for some versatile functionality. I'm trying to get the location of the PApplet window onscreen but without the "frame" class, I can't seem to to do it.

旧方法:

int fX = frame.getX();
or
int fX = frame.getLocationOnScreen().x;

整个过程应该是动态的,因此不能在Processings setup()中设置窗口位置.

The whole thing is supposed to be dynamic, so setting the window location in Processings setup() is not an option.

希望有人可以提供帮助,

Hope somebody can help,

问候!B

推荐答案

最好只使用旧的 frame 变量.

对于大多数这样的事情,您应该使用新的 surface 变量,其类型为 PSurface .您可以查看 PSurface 的源代码

For most things like this, you should use the new surface variable, which is of type PSurface. You can view the source for PSurface here. Reading that, we see that unfortunately, the surface variable doesn't give us access to the frame's position.

由于您无法从 surface 变量获取位置,因此您必须更深入并获得 native 组件(默认情况下, SmoothCanvas 扩展了awt Canvas ).我通过查看 PSurfaceAWT 的源代码(

Since you can't get to the location from the surface variable, you have to go a level deeper and get the native component (in the default case, a SmoothCanvas which extends an awt Canvas). I figured this out by looking at the source for PSurfaceAWT available here.

该代码看起来有些粗俗,因为您必须进行一些强制转换:

The code for that looks a little gross, since you have to do some casting:

import processing.awt.PSurfaceAWT;
import processing.awt.PSurfaceAWT.SmoothCanvas;

void setup(){
  size(200, 200);
}

void draw(){
  background(0);

  int x = ( (SmoothCanvas) ((PSurfaceAWT)surface).getNative()).getFrame().getX();
  text("x: " + x , 20, 20);
}

这篇关于不推荐使用Java和Processing 3.0“框架"类,是否有替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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