Dropping a card on a foundation stack

Now we will write the code to add the dropped card to the stack if the user drops the card in a valid place, or to return the card to its original column if the user drops the card in an invalid place.

  1. In the constructor, in the block of code that created the new MouseAdapter, add a second public method called mouseReleased(). It should take one parameter, a MouseEvent called e, and return nothing. mouseReleased() should:
    • Create integers called x and y, initialized to the x and y coordinate values of e, respectively using MouseEvent’s getX() and getY() methods.
    • Call released(), passing it x and y.

Note: If you execute the code right away after adding these changes, it will have a syntax error because released() does not exist yet.

    ...
 
  public TablePanel() {
 
      ...
 
    addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        clicked(x, y);
      }
      
      ____________ mouseReleased(___________) {
        ______ x = e.______;
        ______ y = e.______;
        released(________);
      }
    });
      ...

Get hands-on with 1200+ tech skills courses.