J'ai une application qui ouvre plusieurs JIF, mais je veux seulement créer une seule instance du JIF, donc j'utilise ces fonctions pour vérifier cela, et j'utilise disposer pour fermer le JIF après qu'une touche est pressée (JDesktopPane.getSelectedFrame().disposer()). Cependant après 2-3 éliminations successives, il ne crée pas un nouveau JIF? Est-ce que je fais quelque chose de mal ici?Gestion d'une seule instance de JInternalFrame?
public static void setInternalFrame(final JInternalFrame internalFrame) {
log.debug("CurActiveInternalFrame " + ShoppyPOSApp.getCurrentActiveInternalFrame(), null);
log.debug("Incoming internalFrame " + internalFrame, null);
boolean isFrameFound = false;
try {
// Have a check whether the DesktopPane contains the internal Frame
// If yes bring it to front and set the focus
for (int i = 0; i < ShoppyPOSApp.frame.mainDesktopPane.getAllFrames().length; i++) {
if (ShoppyPOSApp.frame.mainDesktopPane.getAllFrames()[i].getClass() == internalFrame.getClass()) {
isFrameFound = true;
}
}
if (!isFrameFound) {
internalFrame.setVisible(true);
internalFrame.setLocation(
ShoppyPOSApp.frame.mainDesktopPane.getWidth()/ 2 - internalFrame.getWidth()/2,
ShoppyPOSApp.frame.mainDesktopPane.getHeight()/2 - internalFrame.getHeight()/2
);
ShoppyPOSApp.frame.mainDesktopPane.add(internalFrame);
}
internalFrame.setSelected(true);
} catch (Exception e) {
log.debug(e.toString(), null);
}
}