Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the observer pattern in this case. I assume you have a list of connected people somewhere on each client. if this is some it should be quite simple to notify the other people of the move event. Simply make the ChatPerson observable like so</p> <pre><code>public class ChatPerson { //your props here :P... private final List&lt;MoveListener&gt; listeners = new ArrayList&lt;MoveListener&gt;(); private void notifyListeners(MoveEvent e){ for(MoveListener l : listeners){ l.onMoveEvent(e); } } public void addMoveListener(MoveListener l){ this.listeners.add(l); } public void removeMoveListener(MoveListener l){ this.listeners.remove(l); } //i would create a move method but you can do this on setX() and setY() public void move(int x,int y){ this.x=x; this.y=y; this.notifyListeners(new MoveEvent(this,x,y)); } //your other method... } </code></pre> <p>Now for the MoveListener Interface.</p> <pre><code>public interface MoveListener{ public void onMoveEvent(MoveEvent e); } </code></pre> <p>And the MoveEvent.</p> <pre><code>public class MoveEvent{ public final ChatPerson source;//i could be more generic but you get the ideea public final int currentX; public final int currentY; public MoveEvent(ChatPerson source, int x,int y){ this.source = source; this.currentX = x; this.currentY = y; } //you can make the fields private and getters ofc :P } </code></pre> <p>Now whenever the ChatPerson moves, it broadcast its position in a nice and generic way, its up to each listener to its stuff in response to this event.<br/> In the container class (the one with the list of connected people) simply implement a MoveListener and add it to the current ChatPerson.<br/> In this implementation you can iterate over the list of connected people and send the current position "over the wire" so to speak. Without more detail on how your app is implemented I can't really give a better answer.<br/> Hope it this helps. </p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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