简体   繁体   中英

Java CardLayout: Is it possible to use same object on two different cards?

I am creating a program containing a map. For the GUI I use CardLayout cus I'm swapping between windows. One of the windows in my program is with a smaller map, and another one is with a bigger map.

When I swap between these two windows I want the information (zoom, waypoints etc.) on the map I just looked at to be transfered to the 2nd map. But I figured that the best way to do this (considering I'm gonna need several thousand waypoints for my use (why is not relevant)) is just to let the same object be at both the cards.

Will this be possible? I will simply adjust the location and the size, but everything else (like zoom and waypoints) will be intact!

-Thanks alot :)

PS: I'm using JXMapViewer

You should separate model and view.

Create a custom model with all the info (zoom, waypoints etc.) Create two views - panels which keep reference to the same model object and have own params - location and size.

Place in the CardLayout both views and swap when necessary.

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