title: Getting X & Y coordinates from graphics object
body: <p>I have a problem. I'm creating this maze game using java for the very first time, 
  and I have lots and lots of <code>graphics(g)</code> drawings/objects drawn through their own class.</p>
  
  <p>What I want to get is the <code>X</code> and <code>Y</code> coordinate out of one of them.</p>
  
  <p><code>public static int</code> seems too hard to use in this case, without created an equal number of integers as there are drawings. </p>
  
  <p>So, I need something to use instead of <code>getY()</code>:</p>
  
  <pre><code>public void keyPressed(KeyEvent e){
      int key = e.getKeyCode();
      if (key == KeyEvent.VK_LEFT) {
          for (int i=0; i&lt;=42; i++) {
              if(cx != rektangel[i].getY())  // I tried "getY()" with fail(kind of dumb since it's used for mouselistener?
  
              cirkel[0].move(-10, 0);
              this.cx += -10;
              repaint();
  
  
      }
  }
  </code></pre>
  
  <p>Information you might need to know in this code:</p>
  
  <ul>
  <li><code>rektangel(the name)</code> = rectangle in english.</li>
  <li><code>cirkel</code> is one object/drawing ==> I simply used a <code>static int</code> <code>cx</code> &amp; <code>cy</code> for this guy to see it's coordinates.</li>
  <li>Where it says <code>i&lt;42;</code> ==> shows that it's ALOT of drawn objects. (<code>static int</code> won't be optimal)</li>
  </ul>
  
  <p>=============ANSWERED======ANSWERED=======ANSWERED=======ANSWERED==========
  Sorry, but for some reason I can't comment your answers. The result is ridiculously laughable. I'm currently staying up late to finish my code for a homework I have. Thanks for your solution, and MadProgrammers comment. Here's my rectangle-class:</p>
  
  <pre><code>public class Rektangel {
     private int width,height;
     private int x,y; &lt;---this row private
     Color c;
     public static int karta = 1;
     public static int rx = 0;
     public static int ry = 0;
  }
  </code></pre>
  
  <p>The easiest thing in the world.. I had tried using <code>rectangle[i].x</code> in the previous code, but didn't work. Know why? Because I wrote private instead of public x &amp; y. Sorry for the inconvenience and once again, Thanks!</p>