在JInternalFrame中单击Close(X)按钮时如何执行某些操作

时间:2014-02-26 15:21:03

标签: java swing applet jinternalframe

我有一个分配来创建JInternalFrame,可以调用我的applet工作的多个(最后一个分配调用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);

}

}

我可以毫无问题地调用applet,但我无法计算它们中有多少是“实际”运行的。

创建一个小程序时,我的方法是checkApp++,当关闭一个小程序时,我的方法是checkApp--。 有没有办法使用关闭按钮(X)或类似的听众?

1 个答案:

答案 0 :(得分:7)

  

"是否有办法使用关闭按钮(X)或类似的监听器????"

适当的答案似乎是使用InternalFrameListener,正如Oleg在评论中指出的那样。您可以在How to write InternalFrameListeners

查看更多信息
public class IFrame extends JInternalFrame {

    public IFrame() {
        addInternalFrameListener(new InternalFrameAdapter(){
            public void internalFrameClosing(InternalFrameEvent e) {
                // do something  
            }
        });
    } 
}

<强>侧面注意

  

&#34;我得到了一个创建JInternalFrame的作业,可以调用我的applet工作的多个&#34;

无论是谁给了你这个作业,请告诉他们阅读Why CS teachers should stop teaching Java applets,甚至可能The Use of Multiple JFrames, Good/Bad Practice?。 IMO看起来像是一个无用的无意义的分配,如果要求是你所描述的。

相关问题