Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.util.Vector;
- import java.awt.*;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- /**
- * Created in IntelliJ IDEA
- * by James Thompson.
- * Date: Sep 21, 2009
- * Time: 3:45:28 PM
- */
- public class MouseRecorder extends JFrame {
- private Vector<Point> locs;
- public static void main(String[] args) {
- new MouseRecorder().setVisible(true);
- }
- public MouseRecorder() {
- super("Mouse Recorder");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(700, 500);
- setBackground(Color.white);
- addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- locs.add(new Point(-e.getX(), -e.getY()));
- }
- });
- new Thread(new Runnable() {
- public void run() {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ignored) {
- }
- System.out.println("Recording...");
- locs = new Vector<Point>();
- for (int i = 0; i < 500; ++i) {
- Point loc = getMousePosition();
- if (loc == null)
- break;
- else
- locs.add(loc);
- try {
- Thread.sleep(20);
- } catch (InterruptedException ex) {
- break;
- }
- }
- for (int i = 1; i < locs.size(); i++) {
- Point p = locs.get(i);
- if(p.getX() < 0) {
- System.out.println("[Click\t\t\t] " + -p.getX() + ", " + -p.getY());
- locs.remove(i); i--;
- continue;
- }
- Point po = locs.get(i-1);
- double dist = Math.hypot(p.getX() - po.getX(), p.getY() - po.getY())/20.0;
- System.out.println("[" + i * (20) + "ms\t\t\t] " + p.getX() + ", " + p.getY() + "\t" + dist + "px/ms");
- }
- }
- }).start();
- }
- }
Add Comment
Please, Sign In to add comment