[求助]源代码不理解....请大家给个注释
对源代码不理解啊,那位高手给些注释(最好能详尽些),谢了!1. /* 向量的应用 */
2. import java.util.*;
3. import java.awt.*;
4. import java.awt.event.*;
5. class Point
6. {
7. int x,y;
8. Point(int x,int y)
9. {
10. this.x=x;this.y=y;
11. }
12. }
13.
14. class PaintCanvs extends Canvas implements MouseMotionListener,MouseListener
15. {
16. int x=-1,y=-1;
17. int n=1;
18. Vector v=null;
19. PaintCanvs()
20. {
21. setBackground(Color.cyan);
22. addMouseMotionListener(this);
23. addMouseListener(this);
24. v=new Vector();
25. }
26. public void paint(Graphics g)
27. {
28. if(x!=-1&&y!=-1)
29. {
30. n=v.size();
31. for(int i=0;i<n-1;i++)
32. {
33. Point p1=(Point)v.elementAt(i);
34. Point p2=(Point)v.elementAt(i+1);
35. g.drawLine(p1.x,p1.y,p2.x,p2.y);
36. }
37. }
38. }
39. public void mouseDragged(MouseEvent e)
40. {
41. x=(int)e.getX();
42. y=(int)e.getY();
43. Point p=new Point(x,y);
44. v.addElement(p);
45. repaint();
46. }
47. public void mouseReleased(MouseEvent e)
48. {
49. v.removeAllElements();
50. }
51. public void update(Graphics g)
52. {
53. paint(g);
54. }
55. public void mouseMoved(MouseEvent e) {}
56. public void mousePressed(MouseEvent e){}
57. public void mouseEntered(MouseEvent e){}
58. public void mouseExited(MouseEvent e) {}
59. public void mouseClicked(MouseEvent e){}
60. }
61.
62. public class Example11_2
63. {
64. public static void main(String[] args)
65. {
66. Frame f=new Frame();
67. f.setTitle("向量应用");
68. f.setSize(300,200);
69. f.show();
70. f.add(new PaintCanvs());
71. f.validate();
72. }
73. }