I have a client (android) and a server (computer).
Right now you can draw from the server and it will show the client, and the other way around.
My problem is the drawing function itself. I'm drawing by using lines, but right now there are holes between the lines and I need it fixed.
Need this done asap. Pm me if you're interested. Will pay.
This is what I'm sending from the server side:
Code
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
// save coord x,y when mouse is pressed
startDrawing=true;
oldX = e.getX();
oldY = e.getY();
try {
if (s != null) {
mouseSend = new MouseData(oldX, oldY, currentX, currentY, startDrawing, isDrawing, endDrawing);
out.writeObject(mouseSend);
}
}
catch (IOException ex){
ex.printStackTrace();
}
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
// coord x,y when drag mouse
currentX = e.getX();
currentY = e.getY();
isDrawing = true;
startDrawing=false;
endDrawing=false;
if (g2 != null) {
try {
// draw line if g2 context not null
g2.drawLine(oldX, oldY, currentX, currentY);
if(s!=null) {
mouseSend = new MouseData(oldX, oldY, currentX, currentY, startDrawing, isDrawing, endDrawing);
out.writeObject(mouseSend);
}
// refresh draw area to repaint
repaint();
// store current coords x,y as olds x,y
oldX = currentX;
oldY = currentY;
}
catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
Here's what I'm receiving on the client from the server:
Code
socket = new Socket("192.168.20.7",8080);
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
while(in!=null) {
mouseReceive = (MouseData) in.readObject();
xReceive = mouseReceive.mouseX;
yReceive = mouseReceive.mouseY;
xNew = mouseReceive._nowX;
yNew = mouseReceive._nowY;
startDrawing = mouseReceive.startDrawing;
isDrawing = mouseReceive.isDrawing;
endDrawing = mouseReceive.endDrawing;
}
Here's the function I made on the client that uses the data received from the server to create lines between the points:
Code
public void drawPath() {
invalidate();
if(startDrawing=true){
testx=xReceive;
testy=yReceive;
}
if(isDrawing=true) {
drawCanvas.drawLine(testx, testy, xNew, yNew, drawPaint);
invalidate();
System.out.println(xReceive + " " + yReceive + " " + xNew + " " + yNew);
}
invalidate();
}
It's supposed to draw a smooth path , creating lines between the points, but what I'm getting is holes between points. I followed a tutorial to make a simple drawing function using path and canvas,
which I also tried using to draw the lines from the server, but I just got the same result :/.
This is what is being displayed when I draw on the servers frame:
This post was edited by Polsenols on May 10 2015 12:55pm