Paint program

i want to make a multiplayer pictionary game using client / server.

I have a very simple drawing program like paintbrush, just allows me to paint freehand in black.

Now when one client draws, i want the other clients to view the drawing take place in real time. Whats the best way to stream the data / pixel coordinates out to the server ?

here is the part that draws

      protected class JPaintPanel extends JPanel implements MouseMotionListener, MouseListener
      {
            public JPaintPanel()
            {
                  super() ;
                  addMouseListener(this) ;
                  addMouseMotionListener(this) ;
            }
 
            public void mouseDragged(MouseEvent arg0) 
            {
                  Point p = arg0.getPoint() ;
                  getGraphics().drawLine(lastPos.x, lastPos.y, p.x, p.y) ;
                  lastPos = p ;
            }
            public void mousePressed(MouseEvent arg0)      {lastPos=arg0.getPoint();}
            public void mouseReleased(MouseEvent arg0)       {lastPos=null ;}
 
            public void mouseMoved(MouseEvent arg0) {}
            public void mouseClicked(MouseEvent arg0){}
            public void mouseEntered(MouseEvent arg0) {}
            public void mouseExited(MouseEvent arg0) {}
            
            protected Point lastPos = null ;
      }

I assume Sockets->BuferedOutputStream->DataOutputStream with serialiszing primitives.
Thats the fastest way you can go, but its a bit ugly to implement…

lg Clemens

thanks but what exactly will i be outputting though ?

How would i collect all the pixel data ?

I would send the events themselves. The person drawing invokes a mousePress, send the same mousePress to the server for distribution. Let the clients all handle them in the same way. You don’t need a separate way to interpret the calls when you already have one way to do it. Then you don’t have to worry abou them acting different if they use the same code.

thanks for the suggestion.

I had to redo my code as the image wasnt saving on the panel if i minimized the window. So what i done was … when drawing, it adds the pixel positions to a vector. So now the complete image is stored in a vector.

I was thinking about your suggestion to capture the mouse events, but do you think i could just send the vector data to everyone ?

I dont understand you idea. You are basically storing all the draw events in a vector - was that was you tried to tell us?

Well, you do not need a Vector for storing all paints, why not just transfering paint events to the other clients?
(Btw. draw into an image, than you do not have to “redraw” everytime the window needs a repaint).

lg Clemens

how do i draw into an image ?

sounds like a better way.

Im not storing draw ‘events’ into a vector. During ‘mouseDragged’, it is storing all mouse points (pixel coordinates) into a vector, the program is then redrawing the points at the same time.