簡體   English   中英

如何將實際jFrame的實例傳遞給其他jFrame

[英]How to pass the instance of the actual jFrame to other jFrame

我有兩個類,從第一個jFrame1(CotizacionGUI)實例化並使另一個(jFrame2)可見,我想將此jFrame1(CotizacionGUI)的實例傳遞給構造函數中的另一個,以進行處理隨時可以通過按鈕觸發操作...

public class CotizacionGUI extends javax.swing.JFrame{
    public CotizacionGUI() {
        initComponents();
    }
    private void buttonCallFrame2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        BuscarCotizacionGUI bC = new BuscarCotizacionGUI(thisjFrameinstance);
        bC.setVisible();
    }  
}

這是Frame2(BuscarCotizacionGUI),這是我要處理由動作執行事件觸發的前一個jFrame的地方:

public class BuscarCotizacionGUI extends javax.swing.JFrame {
    public BuscarCotizacionGUI(final JFrame otherFrame) {
        initComponents();
        this.setLocationRelativeTo(null);
        button.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                otherFrame.dispose();
            }
        });
    }    
}

您能幫我嗎,我不想使用其他類,我想在jFrame1中傳遞引用,謝謝!

第一JFrame的實例始終為您提供在同一類this

public class CotizacionGUI extends javax.swing.JFrame{
    public CotizacionGUI() {
        initComponents();
    }
    private void buttonCallFrame2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        BuscarCotizacionGUI bC = new BuscarCotizacionGUI(this);
        bC.setVisible();
    }  
}

希望這是您想要的。
祝好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM