How to acces values from within MouseListener
<p>I am trying to update the value of the variable 'dest' with the mouse location whenever pressed. 
but whenever checking if the value has been updated (in the run method) i see that it has not been. where am i wrong?</p>

<pre><code>public class Boid extends JPanel implements Runnable{   
    private Vector2D dest = new Vector2D(300,300);

    public Boid ()          
        addMouseListener (new MouseAdapter() {          
            public void mousePressed (MouseEvent e) {           
                Boid.this.dest = new Vector2D(e.getX(), e.getY());
                System.out.println("mouse "+Boid.this.squareX);
            }
        });
    }


    public void run(){                      
        System.out.println(dest);       
    }

    public void drawBoid(Graphics g) {
        g.setColor(Color.red);
        g.drawLine((int)pos.getX(), (int)pos.getY(), (int)dest.getX(), (int)dest.getY());
    }

}
</code></pre>

<p>(edited)
i am calling the run method in the following way. not sure this is the right way, i'm moving from processing so this is how i thought it may work...</p>

<pre><code>public class GUI{
    private static Boid b = new Boid();
    private static Timer TT;    

    public static void main(String[] args) {    
            JFrame mainFrame = new JFrame("Boid GUI");
            mainFrame.setLocationRelativeTo(null);
            mainFrame.setResizable(false);
            mainFrame.setSize(640,480);
            mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel contentPanel = new JPanel();
            contentPanel.setPreferredSize(new Dimension(640,480)); 
            contentPanel.setBackground(Color.BLACK);

            mainFrame.add(contentPanel);
            mainFrame.setVisible(true);  

            ActionListener updateDrawing = new ActionListener() {
                public void actionPerformed(ActionEvent e) {                    
                    b.run();                       
                    b.drawBoid(contentPanel.getGraphics());

                }
            };

            TT = new Timer(50, updateDrawing);
            TT.start();
    }
}
</code></pre>

<p>also tried the following main, but seems like the boid.run method then only 'runs' once:</p>

<pre><code>public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

        public void run() {
            JFrame mainFrame = new JFrame("Boid GUI");
            mainFrame.setLocationRelativeTo(null);
            mainFrame.setResizable(false);
            mainFrame.setSize(640,480);
            mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel contentPanel = new JPanel();
            contentPanel.setPreferredSize(new Dimension(640,480)); 
            contentPanel.setBackground(Color.BLACK);

            mainFrame.add(contentPanel);
            setWindow(mainFrame);
            mainFrame.setVisible(true);  

            b.run();
        }
        });
}
</code></pre>