Second post in my first day, but i've hit another major problem with my program.
the co-ordinates for the JPanel start with 0,0 in the top left.
I need them to be bottom left.
Is there an easy way to do this?
One solution i've thought of is rotating the JPanel counterclockwise 90degrees, and then just using the X as the Y and Y as the X.
The problem with that is
I don't know how to rotate the panel.
Flipping x and y over could end up causing me lots of silly issues later on when i have more code to deal with.
Any ideas folks?
As always, thanks in advance!
How are you using these coordinates? What is this for? To draw on the JPanel? To place other components? You know it is easy to calculate the JPanel's dimensions after it has been rendered via the getSize method.
Are you tying to make a graph plotter? If so, just accept that y++ is going down and y-- is going up, x behaves normally.
i am using a JPanel as a 'scene'
I am using Java to create a level editor for an iphone game im working on.
Images get placed into the scene, when a new item is added. It gets added to the top of a list.
Each item in the list knows its position, and knows the 'gap' between it and the item above it.
I have some script which uses this data and generates some Objective-C code for me.
Essentially, rather than having to place sprites, load the app, load the game, check the level, close the app, alter a int value to move an item, repeat, over and over and over. I'm making a visual editor.
On an iPhone, the map runs from bottom to top. 0,0 being bottom left.
If i use the JPanel co-ordinates, my map would 'start' from the top and go down, and so essentially be upside down.
Does that information help?
This is pretty similar to a problem I had, mainly being if you store coordinates in an array, you can't print them out directly to the screen, since in a 2d array, the 'x' or first coordinate denotes height, while screen coordinates have their 'x' denote length. I solved that simply by mirroring the coordinates of the array, so on-screen coordinates 300,400 would become array. In your case, if you simply want the y coordinate reversed, when storing the coordinates of your objects you could do something like:
Not sure about the getHeight() method, should see JPanels API to confirm. So, in essence, if your object is almost at the top-left corner with coordinates lets say 30,20 with a panel height of 200, you'd get 30,180, as if the 0,0 point was in the bottom-left.
yCoord = panel.getHeight() - y; //y denotes jPanel coordinate
^ thats raw manlove up there. haha thx guys