簡體   English   中英

如何在另一個類中獲取JFrame對象運動

[英]How to get JFrame object movement in another class

所以,我有一個Window類,它擴展了 JFrame ,它是更大的窗口。

在此處輸入圖片說明

然后,我有了MathematicalFunvtions類,該類還擴展了 JFrame ,后者是較小的窗口。

我想將它們結合在一起在另一個類“測試”中,以便它們一起工作。

public static void main(String args[]) {       
    Window mainwindow;
    mainwindow = new Window();
    mainwindow.setVisible(true);


    MathematicalFunctions functions;
    functions = new MathematicalFunctions(mainwindow);
}

我這樣做的方法是將Window對象的引用作為MathematicalFunctions的參數,然后讓它完成工作。

  1. 問題是...這是對事物進行編程的好方法嗎?

  2. 當我將mainwindow發送給函數時,我想知道該對象內部,主窗口何時移動...以便該對象可以對其進行跟蹤並進行調整,以使它們始終在一起。

我沒有放棄研究,但最終我得到了……我將這段代碼放在MathematicalFunctions的構造函數中:

mainwindow.addComponentListener(new java.awt.event.ComponentAdapter() {
        @Override
        public void componentMoved(java.awt.event.ComponentEvent evt) {
            GlowneComponentMoved(evt);
        }
    });

//and the listener....
private void GlowneComponentMoved(ComponentEvent evt) 
{
      this.setLocation( (Okno_Glowne.getX()+ Okno_Glowne.getWidth()+10), Okno_Glowne.getY());   
}

並且它應該如何工作。 每次我移動較大的窗口時,都會出現一個小窗口:)

還有更多...我也做了MathematicalFunction類JDialog擴展

public class MathematicalFunctions extends javax.swing.JDialog

和測試類看起來像以前

public static void main(String args[])
{

   oknoo mainwindow;
   mainwindow = new oknoo();
   mainwindow.setVisible(true);


   MathematicalFunctions funkcje;
   funkcje = new MathematicalFunctions(OknoGlowne);
}

;)

暫無
暫無

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

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