在多文档的界面程序中,有若干种文档,也就是有若干种internalframe,要实现saveall命令,要根据其类别作出不同的保存方法,但是当使用getAllIneternalFrames从JDesktopPane中get到所有的internalframe均是JInternalFrame型的,有没有办法判别各自类型?代码大概就如下。新手上路,请各位不吝赐教protected void saveAllUnchangedFrames(){
JInternalFrame[] allFrames=desktop.getAllFrames();
for(int i=0;i<allFrames.length;i++)
{
if(((GaInternalFrame) allFrames[i]).isChanged()){
int state=JOptionPane.showConfirmDialog(this,
"文件"+allFrames[i].getTitle()+"已经改动,要保存么?");
if(state==JOptionPane.YES_OPTION)
saveFrame((GaInternalFrame) allFrames[i]);
else if(state==JOptionPane.NO_OPTION)
return;
}
}

解决方案 »

  1.   

    JInternalFrame.JDesktopIcon 
    This component represents an iconified version of a JInternalFrame.
    刚才帮查了一下,好像是标识JInternalFrame的,不知道对你有没有用。
      

  2.   

    非常感谢 kaleon(为人要厚道),但是这个JInternalFrame.JDesktopIcon 并不是解决问题的方法,在JDK Documentation中说到了:
    This component represents an iconified version of a JInternalFrame. This API should NOT BE USED by Swing applications, as it will go away in future versions of Swing as its functionality is moved into JInternalFrame. This class is public only so that UI objects can display a desktop icon. If an application wants to display a desktop icon, it should create a JInternalFrame instance and iconify it. 
      

  3.   

    仅仅是在internalFrame最小化时出现的图标而已
      

  4.   

    而且在jdk1.5中这个东西已经不太用到了,因为it will go away in future versions of Swing as its functionality is moved into JInternalFrame