title: Stopping java.awt.Robot with a JButton
body: <p>So I'm making a program which utilizes a Robot to copy and paste text. However, I've hit a wall when it comes to how to stop the Robot in the middle of its actions (I prefer using a button since the whole application is in a GUI). Right now I have it so that the Robot is created and starts when a different button is clicked, and it stops after a certain amount of messages. From what I understand you need to stop the thread it's on, but I'm not sure how to do that.</p>
  
  <pre><code>public void initSpam() throws AWTException
  {
  
      Robot bot = new Robot();
      isRunning = true;
  
      int delayTime;
      if(isDefault)
          delayTime = DEFAULT;
      else
          delayTime = customTime;
  
      StringSelection selection = new StringSelection(spam);
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      clipboard.setContents(selection, selection);
  
      bot.delay(1250);
  
      for (int i = 0; i &lt; buffer; i++) {
          bot.keyPress(KeyEvent.VK_CONTROL);
          bot.keyPress(KeyEvent.VK_V);
          bot.keyRelease(KeyEvent.VK_CONTROL);
          bot.keyRelease(KeyEvent.VK_V);
          bot.keyPress(KeyEvent.VK_ENTER);
          bot.keyRelease(KeyEvent.VK_ENTER);
          bot.delay(delayTime);
      }
  
  }
  </code></pre>
  
  <p>The above is the method that's called when the other JButton is pressed. If anyone could guide me how to do this and explain how all of this threading works/how to work with it properly (assume I don't know much), I'd greatly appreciate it. 
  Thank you!</p>