Guest User

Untitled

a guest
Jul 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.util.Vector;
  3. import java.awt.*;
  4. import java.awt.event.MouseAdapter;
  5. import java.awt.event.MouseEvent;
  6.  
  7. /**
  8. * Created in IntelliJ IDEA
  9. * by James Thompson.
  10. * Date: Sep 21, 2009
  11. * Time: 3:45:28 PM
  12. */
  13. public class MouseRecorder extends JFrame {
  14.  
  15. private Vector<Point> locs;
  16.  
  17. public static void main(String[] args) {
  18. new MouseRecorder().setVisible(true);
  19. }
  20.  
  21. public MouseRecorder() {
  22. super("Mouse Recorder");
  23. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24. setSize(700, 500);
  25. setBackground(Color.white);
  26. addMouseListener(new MouseAdapter() {
  27. public void mouseClicked(MouseEvent e) {
  28. locs.add(new Point(-e.getX(), -e.getY()));
  29. }
  30. });
  31. new Thread(new Runnable() {
  32. public void run() {
  33. try {
  34. Thread.sleep(1000);
  35. } catch (InterruptedException ignored) {
  36. }
  37. System.out.println("Recording...");
  38. locs = new Vector<Point>();
  39. for (int i = 0; i < 500; ++i) {
  40. Point loc = getMousePosition();
  41. if (loc == null)
  42. break;
  43. else
  44. locs.add(loc);
  45. try {
  46. Thread.sleep(20);
  47. } catch (InterruptedException ex) {
  48. break;
  49. }
  50. }
  51. for (int i = 1; i < locs.size(); i++) {
  52. Point p = locs.get(i);
  53. if(p.getX() < 0) {
  54. System.out.println("[Click\t\t\t] " + -p.getX() + ", " + -p.getY());
  55. locs.remove(i); i--;
  56. continue;
  57. }
  58. Point po = locs.get(i-1);
  59. double dist = Math.hypot(p.getX() - po.getX(), p.getY() - po.getY())/20.0;
  60. System.out.println("[" + i * (20) + "ms\t\t\t] " + p.getX() + ", " + p.getY() + "\t" + dist + "px/ms");
  61. }
  62. }
  63. }).start();
  64. }
  65.  
  66. }
Add Comment
Please, Sign In to add comment