【发布时间】:2014-03-29 12:52:09
【问题描述】:
我有一个任务要创建一个JInternalFrame,它可以调用我的多个小程序工作(最后一个任务调用SpherePainter),并且可以计算JinternalFrame 中运行了多少“小程序”。
[小程序在另一个JInternalFrame中运行]
public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
public MyInternalFrame() {
super("SpherePainter #" + (++openFrameCount),
true,
true,
true,
true);
setSize(500,500);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
SpherePainterApplet sp = new SpherePainterApplet ();
sp.init();
this.add(sp);
}
}
我可以毫无问题地调用小程序,但我无法计算其中有多少是“实际”运行的。
我的方法是在创建一个小程序时使用checkApp++,在关闭一个小程序时使用checkApp--。
有没有办法使用关闭按钮(X)或类似的监听器?
【问题讨论】:
-
检查 JInternalFrame.addInternalFrameListener() 方法、InternalFrameListener.internalFrameClosing() 和 InternalFrameListener.internalFrameClosed() 侦听器方法以及docs.oracle.com/javase/tutorial/uiswing/events/…的相应教程。
-
它直接到错误 404 页面,但我会尝试你的代码。谢谢
-
好像 oracle 站点有一些奇怪的重写/重定向检查,请尝试转到 docs.oracle.com/javase/tutorial/uiswing/TOC.html 并手动选择主题“如何编写内部帧侦听器”。
标签: java swing applet jinternalframe