gpt4 book ai didi

java - 在 JInternalFrame 中单击关闭 (X) 按钮时如何执行某些操作

转载 作者:行者123 更新时间:2023-12-03 20:29:30 24 4
gpt4 key购买 nike

我接到了创建 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)或类似的监听器?

最佳答案

"Is there a way to use listener of closing button (X) or similar????"



合适的答案似乎是使用 InternalFrameListener正如奥列格在评论中指出的那样。您可以在 How to write InternalFrameListeners 看到更多信息
public class IFrame extends JInternalFrame {

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

旁注

"I got a assignment to create a JInternalFrame that can call mutiple of my applet work"



谁给了你这个作业,告诉他们阅读 Why CS teachers should stop teaching Java applets甚至可能 The Use of Multiple JFrames, Good/Bad Practice? .如果要求是你所描述的,IMO 似乎是一个无用的废话任务。

关于java - 在 JInternalFrame 中单击关闭 (X) 按钮时如何执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com