Here is the main class and below is the thread class MAIN CLASS /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uav; import java.awt.MouseInfo; import java.awt.PointerInfo; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; /** * * @author User */ public class tester { static int startTime = (int) System.currentTimeMillis(); static boolean trigger = false; static JLabel label = new JLabel(); static JLabel status = new JLabel(); static mouseLocate msl = new mouseLocate(); static JButton startButton = new JButton("Begin tracking"); static JButton stopButton = new JButton("Stop Tracker"); static Thread myThread = new Thread(new mouseLocate()); public static void main(String[] args) { JFrame frame = new JFrame("Mouse Grabber"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 100); JPanel panel = new JPanel(); frame.add(panel); panel.add(startButton); startButton.addActionListener(new startAction()); panel.add(stopButton); stopButton.addActionListener(new stopAction()); panel.add(label); panel.add(status); myThread.start(); } static class startAction implements ActionListener { public void actionPerformed(ActionEvent e) { msl.setIsShutingDown(false); System.out.println(msl.isShutingDown); } //RUN //myThread.start(); } static class stopAction implements ActionListener { public void actionPerformed(ActionEvent e) { msl.setIsShutingDown(true); System.out.println(msl.isShutingDown); } } } *********************************************************************** *********************************************************************** *********************************************************************** THREAD CLASS /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uav; import java.awt.MouseInfo; import java.awt.PointerInfo; /** * * @author User */ public class mouseLocate implements Runnable { private boolean trigger = false; private int startTime = (int) System.currentTimeMillis(); static String status = ""; public volatile boolean isShutingDown;; public void run() { int x, y; //isShutingDown = true; while (!isShutingDown) { try { PointerInfo mouseLocation = MouseInfo.getPointerInfo(); x = mouseLocation.getLocation().x; y = mouseLocation.getLocation().y; System.out.println("X:" + x + " Y:" + y + " Elapsed time: " + (((int) System.currentTimeMillis() - startTime) / 100)); } catch (Exception e) { System.out.println("Exception caught : " + e); } } } public void shutDown() { isShutingDown = true; } public int getStartTime() { return startTime; } public void setStartTime(int startTime) { this.startTime = startTime; } public boolean isTrigger() { return trigger; } public void setTrigger(boolean trigger) { this.trigger = trigger; } public static String getStatus() { return status; } public static void setStatus(String status) { mouseLocate.status = status; } public boolean isIsShutingDown() { return isShutingDown; } public void setIsShutingDown(boolean isShutingDown) { this.isShutingDown = isShutingDown; } }