wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Clean way to change between mutlible pictures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clean way to change between mutlible pictures" Watch "Clean way to change between mutlible pictures" New topic

Clean way to change between mutlible pictures

svein kristian nykaas

Joined: Apr 15, 2012
Posts: 11
Hello, I want to make a game, but before even attempting that I want to get some of the basics of it down and generally have a rather ok\clean code to work from.

What I am basically trying to have is a picture that shows like a world-map, and when you click on some part of the world-map your taken to a new picture showing a bit more detailed information of the area(and so on depending on amount of areas).

The way I'm doing this is to get the x\y coordination from the mouse, and then change the picture to another picture if it is within the coordination, however this would mean I'd need unthinkable amount of if\else statements, especially considering different conditions and states(which is fine, but it seems way too unorganized).

I did try to create a class for each location, however when I did that I didn't manage to neither go back or change to another location(which was another class itself).

So I'm just wondering, is there any cleaner ways to do this then having either a million of functions for each location within 1 class? Or having it all spammed down with lots of if\else's and\or functions in the main class?

*The code of the latest attempt*

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
one way might be to consider your main map like a grid, and each smaller map fits one of the grid squares.

e.g. main map is (500,500) so make each smaller map (50,50), so you have a 10 x 10 grid
with these smaller maps in a 2D array[10][10]
lets say user clicks at (246,180), you'd then show the map from array[246/50][180/50]
svein kristian nykaas

Joined: Apr 15, 2012
Posts: 11
Good suggestion, but I can't really picture it done that way.

as you can see bellow, that's basically how you travel the "world" and to different locations etc. So need some way to make each location unique, but also generally easily accessable by going back and forth.


"after clicking the mountain"

"after clicking the forest"

"after clicking the cottage in the forest"
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
after looking at the pics, I'd still be inclined to create multiple rectangles around the specific areas,
keeping those rectangles in an array, looping the array to see if rectangle.contains(pointClicked),
if true, show the zoomed image of that location/rectangle.

repeat for the zoomed locations/rectangles.

e.g. you mention a world map, rectangles around each continent, as a starter?
all the way down to the pic of the cottage in the forest, where I'd imagine the only
thing to zoom in on is the cottage, so that would be the only rectangle in that image,
clicking anywhere else would do nothing.
I agree. Here's the link: http://aspose.com/file-tools
subject: Clean way to change between mutlible pictures
Similar Threads
how to jude button1 & button are clicked simultaneously?
GUI Issues. Ghosting when moving JLabel via Mouse
Resize JLable Runtime with selection border
setBounds() does not work????
How to get default menu items from JDialog?