处理中的不可预测行为
我刚刚开始在Processing 中创建一个应用程序,当我使用BorderLayout.CENTER 将PApplet 对象放入JFrame 中时,我遇到了不可预测的行为。
PApplet 的宽度比 JFrame 的宽度和高度小 100。 在某些情况下,当我单击“运行”时,程序会填满屏幕并运行得非常流畅,但在其他运行中,PApplet 从左上角开始,并在屏幕底部和左侧留下 100 的间隙,并且相当滞后。
老实说,我不知道发生了什么。
这是顺利运行的结果:
这是不可预测的结果:
这是我正在使用的代码:
PApplet subclass
public class JCanvas extends PApplet {
/**
* PApplet method - performs all setup actions
*/
public void setup(){
size(1400,900,P3D);
background(80);
}
/**
* PApplet method - All drawing occurs here
*/
public void draw(){
background(80);
pushMatrix();
translate(mouseX,mouseY, -199);
fill(220,0,0);
box(120,500,90);
popMatrix();
}
}
Viewer class
public final class EuroViewer {
private final static int WIDTH = 1500;
private final static int HEIGHT = 1000;
private final static boolean RESIZABLE = false;
public static void main(String[] arguments){
final JFrame frame = new JFrame("Eurographics PApplet");
JCanvas sketchCanvas = new JCanvas();
frame.add( sketchCanvas );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(RESIZABLE);
frame.setLocationRelativeTo(null);
sketchCanvas.init();
frame.setVisible(true);
}
}
然后我尝试将 JFrame 替换为awt.Frame 以防在这种特殊情况下 Swing 和 awt(我相信 PApplet 是基于 awt 构建的)之间存在一些稳定性问题。
但令人惊讶的是,Frame 从来没有出现任何延迟,这在一定程度上解决了这个问题。但是,我一直使用 JFrame,任何与容器一起使用的 GUI 都使用 Swing,所以我想知道是否有人可以分享他们的知识并解释发生了什么,以及是否可以修复?这个问题。
谢谢。
I've just started creating an application in Processing, and I'm getting unpredictable behaviour when I place a PApplet object into a JFrame using BorderLayout.CENTER.
The width of the PApplet is 100 less than the width and height of the JFrame.
On some occasions, when I click 'Run', the program fills the screen and runs really smoothly, but on other runs, the PApplet starts from the top left and leaves a gap on 100 on the bottom of the screen and left hand side, and is quite laggy.
I have no idea what is going on if I'm honest.
This is the result which runs smoothly:
This is the unpredictable one:
Here is the code I'm using:
PApplet subclass
public class JCanvas extends PApplet {
/**
* PApplet method - performs all setup actions
*/
public void setup(){
size(1400,900,P3D);
background(80);
}
/**
* PApplet method - All drawing occurs here
*/
public void draw(){
background(80);
pushMatrix();
translate(mouseX,mouseY, -199);
fill(220,0,0);
box(120,500,90);
popMatrix();
}
}
Viewer class
public final class EuroViewer {
private final static int WIDTH = 1500;
private final static int HEIGHT = 1000;
private final static boolean RESIZABLE = false;
public static void main(String[] arguments){
final JFrame frame = new JFrame("Eurographics PApplet");
JCanvas sketchCanvas = new JCanvas();
frame.add( sketchCanvas );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(RESIZABLE);
frame.setLocationRelativeTo(null);
sketchCanvas.init();
frame.setVisible(true);
}
}
I then tried to replace JFrame with awt.Frame incase there was some stability issues between Swing and awt (which I'm led to believe PApplet is built off of) in this paticular case.
Surprisingly enough though, there is never any lag with Frame, which has kind of solved the issue. But, I've always used JFrame, any GUI work with containers etc I've always done with Swing, so I was wondering if anyone could share their knowledge and explain what is going on, and if it would be possible to fix? this issue.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不建议将处理草图与 Swing 结合使用。不可预测的行为已被多次报道。
It’s not recommended to combine Processing sketches with Swing. Unpredictable behavior has been reported a lot of times.