2013-02-14 83 views
0

我一直在使用淨豆開發的應用程序,JInternalFrame的Netbeans的單個實例

1)我在做項目的Java API 6.我使用的是「淨豆7.1」。 2)我想在我的項目中使用JInternalFrame 3)我製作了另一個包,並在那裏製作了「JInternalFrame」。然後通過在「JMenuItem」上觸發執行事件來在我的主應用程序窗口中調用它。 4)它工作正常,但只有一個問題發生,即如果我再次點擊「JMenuItem」,同一實例的新「JInternalFrame」打開,我該如何阻止? 5)我想要的,如果我打開「JInternalFrame」一次,然後再次點擊「JMenuItem」打開相同的「JInternalFrame」,它應該什麼也不做,或者它顯示已經打開並最小化的窗口

sample代碼:

<code> 
private void empDataActionPerformed(java.awt.event.ActionEvent evt) { 
Emps employees = new Emps(); 
desktop.add(employees); 
employees.setVisible(true); 
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
employees.setBounds(230, 40, screenSize.width/2 - 80, screenSize.height/2 + 105); 
} 
<code> 

請我需要幫助。

回答

0

以下是可能的示例代碼。希望這個幫助。 菜單操作調用其中JdesktopPane的主應用程序中的內部框架。

private void YourJinternalFrameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {             

    YourJinternalFrame nw = YourJinternalFrame.getInstance(); 
    nw.pack(); 
    //usefull part for you.. if open shows, if not creates new one 
    if (nw.isVisible()) { 
    } else { 
     desktopPane.add(nw); 
     nw.setVisible(true); 
    } 
    try { 

     nw.setMaximum(true); 
    } catch (PropertyVetoException ex) { 
     Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 

把這個你YourJinternalFrame內

private static YourJinternalFrame myInstance; 

public static YourJinternalFrame getInstance() { 
    if (myInstance == null) { 
    myInstance = new YourJinternalFrame(); 
    } 
return myInstance;