简体   繁体   中英

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(). It returns a Point, which I then passed on the the new menu each time I created it.

When I created the new menu all I had to do was:

new InfoScreen(getLocation());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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