繁体   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