2

以下の「コード パート 1」は、MDI アプリケーションで menuItem から UcakListesi(JinternalFrame) を問題なく呼び出すために使用されます。

同じコードを使用して別の JinternalFrame から同じ UcakListesi(JinternalFrame) を呼び出したいのですが、「desktopPane.add(nw);」に関するエラーが発生します。行はコードパート2を参照してください。JinternalFrameからメインのjframeデスクトップペインにアクセスできません..

JinternalFrame から他の JinternalFrame を呼び出す方法はありますが、メイン Jframe の desktopPane 内にあります。

私の下手な英語でごめんなさい。

よろしくお願いします。

---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);

 }}
4

2 に答える 2

3

私は解決策を見つけました。

Jframe と JDesktopPane 内のコードを以下に配置する最初のクラス (MainApplication) の場合

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 のインスタンスを 1 つだけ取得するには、次のコードを呼び出された JinternalFrame(YourJinternalFrame) に配置します。

private static YourJinternalFrame myInstance;

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

ありがとう:)

于 2013-03-25T21:15:58.997 に答える
0

まず、f2 ボタン アクションで f1 フレーム オブジェクトを作成します。

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();
于 2016-09-20T06:33:11.517 に答える