简体   繁体   English

如何根据以前的现有 JFrame 设置 JFrame 的位置

[英]How to set the location of a JFrame based upon a previous existing JFrame

I am currently writing a program that has a main menu, and then smaller menus branching off of it.我目前正在编写一个程序,它有一个主菜单,然后是从它分支出来的小菜单。 There are currently two menus, the main menu and the info menu.目前有两个菜单,主菜单和信息菜单。 When I click the button to move to the next menu, I want the next Menu to be in the same spot on the screen as the previous.当我单击按钮移至下一个菜单时,我希望下一个菜单与前一个菜单位于屏幕上的同一位置。 The way I am doing this is by passing in the frame to the next Object.我这样做的方法是将帧传递给下一个对象。 This has worked so far, but now, when I try to go back from the second to the first, the location will not work.到目前为止,这已经奏效,但是现在,当我尝试从第二个返回到第一个时,该位置将不起作用。 I know why, but I cannot find my way around the problem.我知道为什么,但我找不到解决问题的方法。 Thanks for any help you can give.谢谢你提供的所有帮助。

I used the getLocation() method, which involves importing java.awt.Component().我使用了 getLocation() 方法,该方法涉及导入 java.awt.Component()。 It returns a Point, which I then passed on the the new menu each time I created it.它返回一个 Point,然后我每次创建它时都将它传递给新菜单。

When I created the new menu all I had to do was:当我创建新菜单时,我所要做的就是:

new InfoScreen(getLocation());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM