Note that there are some explanatory texts on larger screens.

plurals
  1. POJava MVC - problems adding a MouseListener
    primarykey
    data
    text
    <p>I am a Java student and just ended the basic functionality of a little command line card game. The game is a simplified version of Magic-type trading card game. There is no AI, you play against yourself or another human player. </p> <p>At this point, i am trying to add some GUI to it using MVC, but <strong>i'm finding problems adding a MouseListener to a button</strong>.</p> <p>This is a brief explanation of what's going on:</p> <ul> <li>I have a <code>Model</code> class, that extends <code>Observable</code> by inheritance of a superclass</li> <li>A <code>View</code> class, that implements <code>Observer</code>.</li> <li>And a <code>Controller</code> class that extends <code>MouseAdapter</code></li> </ul> <p>Then i put everything together:</p> <pre><code>.... View view = new View(); Model model = new Model(); model.addObserver( view ); Controller controller = new Controller(); // associate Controller's Model and View objects controller.addModel(model); controller.addView(view); view.addController(controller); // i try to add the MouseListener .... </code></pre> <p>The addController() method of View is:</p> <pre><code>public void addController(Controller controller){ this.myButton.addMouseListener( controller ) } </code></pre> <p>I already checked that <code>addController()</code> method is being called (println something inside it), but the Listener is not being set for some reason: <code>mouseReleased()</code> is never called when i click the button.</p> <p>Any thoughts or any step that i may have overlooked? Appreciate.</p> <p><strong>Edit (Controller code):</strong></p> <pre><code>public class Controller extends MouseAdapter { Model model; View view; public void addModel(Model m){ this.model = m; } public void addView(View ui){ this.view = ui; } // All @Overrides @Override public void mouseReleased(MouseEvent me) { System.out.println("oh, it arrived"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload