我想要一个可以加载其他程序的简单程序。 到目前为止,它工作得很好,除非我关闭一帧所有帧都关闭(退出代码为0)。我怎样才能防止这种情况发生?
public class AllSketches extends PApplet {
public static void main(String[] args) {
PApplet.main("forMyself.AllSketches", args);
}
// here all sketches we want
P5_BackFaceCulling backFaceCulling;
public void setup() {
}
public void draw() {
}
public void keyPressed() {
if (key == '1') {
// this creates a new window,
// but when I close it then both windows gets closed!
backFaceCulling = new P5_BackFaceCulling();
backFaceCulling.main(new String[]{});
Frame f = backFaceCulling.getFrame();
if (f instanceof JFrame) {
((JFrame)f).setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
}
}
为了更清楚: 如果我关闭其中一个,则程序退出。 我想要的是,如果我关闭右边的框架,它只关闭右边的框架。 (如果我关闭左边的那个,那我就不关心这个行为了。)
答案 0 :(得分:0)
这是由于Jframe的setDefaultCloseOperation
。你有:
DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
您可能正在使用EXIT_ON_CLOSE
。请改为DISPOSE_ON_CLOSE
。
答案 1 :(得分:0)
我加载的草图是P3D。
因此getFrame()
没有返回JFrame
,而是返回其他类型的框架。