I got a assignment to create a JInternalFrame
that can call mutiple of my applet work (last assignment call SpherePainter
) and can count how many 'applets' are running inside the JinternalFrame
.
[the applet are running inside another 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);
}
}
I can call the applet with no problem, but I cannot count how many of them are 'actually' running.
My method is to checkApp++
when one applet is create and checkApp--
when one is closed.
Is there a way to use listener of closing button (X) or similar?
"Is there a way to use listener of closing button (X) or similar????"
The appropriate answer seems to be to use an InternalFrameListener
as Oleg pointed out in the comment. You can see more at How to write InternalFrameListeners
public class IFrame extends JInternalFrame {
public IFrame() {
addInternalFrameListener(new InternalFrameAdapter(){
public void internalFrameClosing(InternalFrameEvent e) {
// do something
}
});
}
}
Side-Note
"I got a assignment to create a JInternalFrame that can call mutiple of my applet work"
Whoever gave you this assignment, tell them to read Why CS teachers should stop teaching Java applets and possibly even The Use of Multiple JFrames, Good/Bad Practice?. IMO it seems like a useless nonsense assignment, if the requirements are how you described.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With