I am really stuck on what may be fundamental architectural understanding of how to implement an MVC ( Model-View) Java Application. Any help is really appreciated.
I have implemented a pretty standard MouseListener in a Jframe. How do I get the mouse click data out of the Listener and into another thread. Most of the online examples show the manipulation of the event data within the scope of the listener object. Something like this is pretty typical:
public class GUI extends JFrame{
public GUI() {
myCanvas = new DrawCanvas();
MouseAdapter mouser = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
System.out.format( "mouse coor: %d %d\n",e.getX(),e.getY() );
// STUFF ALL YOUR CODE HERE USING e.getX() and e.getY() FOR MOUSE DATA
}
};
myCanvas.addMouseListener(mouser);
Container cp = getContentPane();
cp.add(myCanvas, BorderLayout.CENTER);
}
}
class DrawCanvas extends JPanel {
..............
}
This is great for a nice simple example. But to keep the design modular I have another thread (Model) elsewhere. In addition, I have other listeners such as KeyAdapters, etc... How do I aggregate all these inputs into an object that can be grabbed by another thread. It seems I can't get e.getX() outside the scope of the MouseAdapter instantiation.
And then i have the same problem of how do I get the model data (graphics) back into the JFrame once it has been computed.