|
|
|
|
2
|
|
2
|
|
3
|
|
3
|
|
4
|
import java.awt.BasicStroke;
|
4
|
import java.awt.BasicStroke;
|
5
|
-import java.awt.BorderLayout;
|
|
|
6
|
import java.awt.Color;
|
5
|
import java.awt.Color;
|
7
|
import java.awt.Graphics;
|
6
|
import java.awt.Graphics;
|
8
|
import java.awt.Graphics2D;
|
7
|
import java.awt.Graphics2D;
|
9
|
import java.awt.Point;
|
8
|
import java.awt.Point;
|
10
|
-import java.awt.event.ActionEvent;
|
|
|
11
|
-import java.awt.event.ActionListener;
|
|
|
12
|
import java.awt.event.MouseAdapter;
|
9
|
import java.awt.event.MouseAdapter;
|
13
|
import java.awt.event.MouseEvent;
|
10
|
import java.awt.event.MouseEvent;
|
14
|
import java.awt.event.MouseMotionAdapter;
|
11
|
import java.awt.event.MouseMotionAdapter;
|
15
|
import java.awt.geom.Line2D;
|
12
|
import java.awt.geom.Line2D;
|
16
|
-import java.io.BufferedWriter;
|
|
|
17
|
import java.io.DataInputStream;
|
13
|
import java.io.DataInputStream;
|
18
|
import java.io.DataOutputStream;
|
14
|
import java.io.DataOutputStream;
|
19
|
import java.io.IOException;
|
15
|
import java.io.IOException;
|
|
|
|
|
24
|
|
20
|
|
25
|
import javax.swing.JFrame;
|
21
|
import javax.swing.JFrame;
|
26
|
import javax.swing.JPanel;
|
22
|
import javax.swing.JPanel;
|
27
|
-import javax.swing.JScrollPane;
|
|
|
28
|
-import javax.swing.JTextArea;
|
|
|
29
|
-import javax.swing.JTextField;
|
|
|
30
|
|
23
|
|
31
|
import com.google.gson.Gson;
|
24
|
import com.google.gson.Gson;
|
32
|
import com.google.gson.reflect.TypeToken;
|
25
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
41
|
private List<List<Point>> drawingPoint = new ArrayList<List<Point>>();
|
34
|
private List<List<Point>> drawingPoint = new ArrayList<List<Point>>();
|
42
|
private DataOutputStream drawingOutputStream;
|
35
|
private DataOutputStream drawingOutputStream;
|
43
|
private DrawingInputThread drawingInputThread;
|
36
|
private DrawingInputThread drawingInputThread;
|
|
|
37
|
+ private Gson gson = new Gson();;
|
44
|
|
38
|
|
45
|
class DrawingInputThread extends Thread{
|
39
|
class DrawingInputThread extends Thread{
|
46
|
private Socket socket;
|
40
|
private Socket socket;
|
|
|
|
|
55
|
dis = new DataInputStream(socket.getInputStream());
|
49
|
dis = new DataInputStream(socket.getInputStream());
|
56
|
while(true) {
|
50
|
while(true) {
|
57
|
String line = dis.readUTF();
|
51
|
String line = dis.readUTF();
|
58
|
- Gson gson = new Gson();
|
|
|
59
|
drawingPoint = gson.fromJson(line, new TypeToken<List<List<Point>>>(){}.getType());
|
52
|
drawingPoint = gson.fromJson(line, new TypeToken<List<List<Point>>>(){}.getType());
|
60
|
System.out.println(drawingPoint);
|
53
|
System.out.println(drawingPoint);
|
61
|
repaint();
|
54
|
repaint();
|
|
|
|
|
97
|
|
90
|
|
98
|
addMouseMotionListener(new MouseMotionAdapter() {
|
91
|
addMouseMotionListener(new MouseMotionAdapter() {
|
99
|
public void mouseDragged(MouseEvent event) {
|
92
|
public void mouseDragged(MouseEvent event) {
|
100
|
- Point p = event.getPoint();
|
|
|
101
|
- Gson gg = new Gson();
|
|
|
|
|
93
|
+
|
102
|
point.get(point.size()-1).add(event.getPoint());
|
94
|
point.get(point.size()-1).add(event.getPoint());
|
103
|
// repaint();
|
95
|
// repaint();
|
104
|
System.out.println("mouseDragged " + point.size());
|
96
|
System.out.println("mouseDragged " + point.size());
|
105
|
try {
|
97
|
try {
|
106
|
- drawingOutputStream.writeUTF(gg.toJson(point));
|
|
|
|
|
98
|
+ drawingOutputStream.writeUTF(gson.toJson(point));
|
107
|
} catch (IOException e) {
|
99
|
} catch (IOException e) {
|
108
|
// TODO Auto-generated catch block
|
100
|
// TODO Auto-generated catch block
|
109
|
e.printStackTrace();
|
101
|
e.printStackTrace();
|