use*_*146 2 java applet swing jinternalframe
我有一个任务来创建一个JInternalFrame可以调用我的applet工作的多个(最后一个分配调用SpherePainter)并且可以计算在其中运行了多少'applet' 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);
}
Run Code Online (Sandbox Code Playgroud)
}
我可以毫无问题地调用applet,但我无法计算它们中有多少是"实际"运行的.
我的方法是checkApp++在创建一个applet和checkApp--关闭一个applet 时.有没有办法使用关闭按钮(X)或类似的听众?
"有没有办法使用关闭按钮(X)或类似的侦听器????"
适当的答案似乎是使用InternalFrameListener评论中指出的Oleg.您可以在如何编写InternalFrameListeners中查看更多内容
public class IFrame extends JInternalFrame {
public IFrame() {
addInternalFrameListener(new InternalFrameAdapter(){
public void internalFrameClosing(InternalFrameEvent e) {
// do something
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
边注
"我有一个任务来创建一个可以调用我的applet工作的多个JInternalFrame"
无论谁给你这个作业,告诉他们为什么CS教师应该停止教Java小程序,甚至可能使用多个JFrame,好/坏练习?.IMO似乎是一个无用的无意义的任务,如果要求是你描述的.