2013-03-24 2 views
2

«Кодовая часть 1» ниже используется для вызова UcakListesi (JinternalFrame) из меню в приложении MDI без проблем.есть ли какой-либо способ вызвать другой JinternalFrame из JinternalFrame, но в desktopPane основного Jframe.

Я хотел бы назвать тот же UcakListesi (JinternalFrame) из другого JinternalFrame, используя тот же код, однако я получаю сообщение об ошибке «desktopPane.add (nw);» line см. часть кода 2. Невозможно получить доступ к основному jframe desktopPane form JinternalFrame ..

есть ли какой-либо способ вызвать другой JinternalFrame из JinternalFrame, но в desktopPane основного Jframe.

Извините за мой плохой английский.

С уважением, спасибо.

---code part 1--- 
private void UckListeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {             
    //Uçak listesi penceresi çağrılıyor 
    UcakListesi nw = UcakListesi.getInstance(); 
    nw.pack(); 
    if (nw.isVisible()) { 
    } else { 
     desktopPane.add(nw); 
     nw.setVisible(true); 
    } 
    try { 
     //açılan internal frame'in max size ile açılması için 
     nw.setMaximum(true); 
    } catch (PropertyVetoException ex) { 
     Logger.getLogger(AnaUygulama.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 
---code part 2--- 
class PopUpx extends JPopupMenu { 
JMenuItem anItem1; 
JMenuItem anItem2; 
JMenuItem anItem3; 
JMenuItem anItem4; 
JMenuItem anItem5; 
JSeparator anSeparator1; 
JSeparator anSeparator2; 
JSeparator anSeparator3; 
JSeparator anSeparator4; 
JMenu yeni; 
ActionListener anListener2; 



public PopUpx(final String x){ 
    anItem1 = new JMenuItem(x+ " numaralı Uçak için"); 
    anItem2 = new JMenuItem("Detay Bilgiler"); 
    anItem3 = new JMenuItem("Arıza İş Emri Aç"); 
    anItem4 = new JMenuItem("Uçuş Öncesi Servis"); 
    anItem5 = new JMenuItem("Uçuş Sonrası Servis"); 
    anSeparator1 = new JSeparator(); 
    anSeparator2 = new JSeparator(); 
    anSeparator3 = new JSeparator(); 
    anSeparator4 = new JSeparator(); 
    yeni = new JMenu ("Servis İşlemleri"); 


    add(anItem1); 
    anItem1.setEnabled(false); 
    add(anSeparator1); 
    add(anItem2); 
    anItem2.addActionListener(new ActionListener() { 

      @Override 
     public void actionPerformed(ActionEvent event) { 
      System.out.println(x+" nolu uçağın "+anItem2.getText()+" basıldı"); 

      UcakListesi nw = UcakListesi.getInstance(); 
    nw.pack(); 

    if (nw.isVisible()) { 
    } else { 

     //problem is here 
     desktopPane.add(nw); 
     nw.setVisible(true); 
    } 
    try { 
     //açılan internal frame'in max size ile açılması için 
     nw.setMaximum(true); 
    } catch (PropertyVetoException ex) { 
     Logger.getLogger(AnaUygulama.class.getName()).log(Level.SEVERE, null, ex); 
    } 

     } 

    }); 



    anItem2.setToolTipText(x+ " numaralı Uçağın Detay Bilgilerine ulaşılır..."); 


    add(anSeparator2); 
    add(anItem3); 
    add(anSeparator3); 
    yeni.add(anItem4); 
    add(anSeparator4); 
    add(yeni); 
    yeni.add(anItem4); 
    yeni.add(anSeparator4); 
    yeni.add(anItem5); 

}} 

ответ

3

Я нашел решение.

для первого класса (MainApplication), где ваш JFrame и JDesktopPane внутри места ниже код

public javax.swing.JDesktopPane getDesktopPane() { 
    return desktopPane; 
} 

затем использовать в любом файле класса JInternalFrame, как это назвать еще один (YourJinternalFrame)

YourJinternalFrame nw = YourJinternalFrame.getInstance(); 
    nw.pack(); 
    if (nw.isVisible()) { 
    } else { 
     getDesktopPane().add(nw); 
     nw.setVisible(true); 
    } 
    try { 
     nw.setMaximum(true); 
    } catch (PropertyVetoException ex) { 
     Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); 
    } 

чтобы получить только один экземпляр вызываемого JinternalFrame , введите этот код в названии JinternalFrame (YourJinternalFrame)

private static YourJinternalFrame myInstance; 

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

Спасибо мне :)

0

Сначала создайте объект f1 f2 кадров на кнопку действия

F1 f1 = new F1(); 

Затем создайте объект JDesktopPane как этот

JDesktopPane desktopPane = getDesktopPane(); 
desktopPane.add(f1);//add f1 to desktop pane 
f1.setVisible(true);// set the f1 frame visible 

Наконец, если необходимо утилизировать текущий кадр

this.dispose(); 
Смежные вопросы