coordinates stored in a getPoint() object
<p>I am having a problem with the following code. My intent is to store the coordinates of a mouse click into an arraylist using getPoint, and then draw a rectangle at each location that the user has clicked. I have searched high and low for how to extract the x and y coordinates individually from a getPoint object to no avail. I am new to java, the line that is giving me trouble at compile time is:</p>

<p>g2.drawRect(coordinateList(j).getHeight(),coordinateList(j.getWidth(),3,3);</p>

<p>I know that I am probably way off, but how can I extract the x and y coordinates of a point individually from an array list, one item of the array by one in order to repaint a rectangle at the new click point and also all the previous clicks as well?</p>

<pre><code>import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.event.MouseListener;
import java.awt.Point;
import java.util.*;

public class ClickCloud extends JPanel
{
    private int pointxy;
    //private Rectangle2D.Double r1;
    private boolean mouseClick;
    private int count;
    //private Point[] points;
    private Point coordinates = new Point(0, 0);
    private ArrayList&lt;Point&gt; coordinateList = new ArrayList&lt;Point&gt;();

    public ClickCloud() {
        this.setPreferredSize(new Dimension(500,500));
        this.addMouseListener(new MyMouseListener());
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g; 
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);

        for (int j = 0; j &lt; count; j++) {
            g2.setStroke(new BasicStroke(1.0f));
            g2.setPaint(Color.BLUE);
            g2.drawRect(coordinateList(j).getHeight(),coordinateList(j.getWidth(),3,3);
        }
    }

    private class MyMouseListener implements MouseListener {
        public void mouseClicked(MouseEvent me) { 
            count++;
            coordinates.setLocation(me.getPoint());
            coordinateList.add(coordinates.getLocation());
            repaint();
        }
        public void mousePressed(MouseEvent me) { }
        public void mouseReleased(MouseEvent me) { }
        public void mouseEntered(MouseEvent me) { }
        public void mouseExited(MouseEvent me) { }
    }

     public static void main(String[] args) {
        JFrame f = new JFrame("ClickCloud demo");
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.setLayout(new FlowLayout());
        f.add(new ClickCloud());
        f.pack();
        f.setVisible(true);        
    }
}
</code></pre>

<p>Thanks,</p>

<p>T</p>
