|
@@ -0,0 +1,84 @@
|
|
1
|
+package kr.co.swh.lecture.opensource.ocr;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+import java.awt.BasicStroke;
|
|
5
|
+import java.awt.Color;
|
|
6
|
+import java.awt.Graphics;
|
|
7
|
+import java.awt.Graphics2D;
|
|
8
|
+import java.awt.Point;
|
|
9
|
+import java.awt.event.MouseAdapter;
|
|
10
|
+import java.awt.event.MouseEvent;
|
|
11
|
+import java.awt.event.MouseMotionAdapter;
|
|
12
|
+import java.awt.geom.Line2D;
|
|
13
|
+import java.util.ArrayList;
|
|
14
|
+import java.util.List;
|
|
15
|
+
|
|
16
|
+import javax.swing.JFrame;
|
|
17
|
+import javax.swing.JPanel;
|
|
18
|
+
|
|
19
|
+import com.google.gson.Gson;
|
|
20
|
+
|
|
21
|
+public class LineDraw_Solution extends JPanel {
|
|
22
|
+ private List<List<Point>> point = new ArrayList<List<Point>>();
|
|
23
|
+
|
|
24
|
+// private static Circle circle;
|
|
25
|
+// public static Circle getSingleton() {
|
|
26
|
+// if(circle == null) circle = new Circle();
|
|
27
|
+// return circle;
|
|
28
|
+// }
|
|
29
|
+
|
|
30
|
+ public LineDraw_Solution() {
|
|
31
|
+// Circle c = Circle.get();
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+ addMouseListener(new MouseAdapter() {
|
|
35
|
+ public void mousePressed(MouseEvent event) {
|
|
36
|
+ List<Point> list = new ArrayList<Point>();
|
|
37
|
+ point.add(list);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ @Override
|
|
41
|
+ public void mouseClicked(MouseEvent e) {
|
|
42
|
+ // TODO Auto-generated method stub
|
|
43
|
+
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ });
|
|
47
|
+
|
|
48
|
+ addMouseMotionListener(new MouseMotionAdapter() {
|
|
49
|
+ public void mouseDragged(MouseEvent event) {
|
|
50
|
+ Point p = event.getPoint();
|
|
51
|
+ Gson gg = new Gson();
|
|
52
|
+ System.out.println(gg.toJson(point));
|
|
53
|
+ point.get(point.size()-1).add(event.getPoint());
|
|
54
|
+ repaint();
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ });
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ public void paintComponent(Graphics g) {
|
|
62
|
+ super.paintComponent(g);
|
|
63
|
+ Graphics2D g2 = (Graphics2D) g;
|
|
64
|
+ g2.setColor(new Color(0, 0, 128));
|
|
65
|
+ g2.setStroke(new BasicStroke(15f,
|
|
66
|
+ BasicStroke.CAP_ROUND,
|
|
67
|
+ BasicStroke.JOIN_ROUND));
|
|
68
|
+ for (int i = 0; i < point.size(); i++) {
|
|
69
|
+ List<Point> l = point.get(i);
|
|
70
|
+ for (int j = 1; j < l.size(); j++) {
|
|
71
|
+ g2.draw(new Line2D.Float(l.get(j-1), l.get(j)));
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ public static void main(String[] args) {
|
|
77
|
+// Thread.currentThread().getContextClassLoader().getResourceAsStream("db.pro")
|
|
78
|
+ JFrame f = new JFrame();
|
|
79
|
+ f.add(new LineDraw_Solution());
|
|
80
|
+ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
81
|
+ f.setSize(800, 600);
|
|
82
|
+ f.setVisible(true);
|
|
83
|
+ }
|
|
84
|
+}
|