title: How do event listeners constantly poll to check to see if a button, for example, was clicked?
body: <p>How does, for example, a button in Java actually listen for an event to occur? I understand button events are handled once they are clicked in a special <strong>EDT (Event Dispatching Thread)</strong>. But how without "busy waiting" does the button know that it has been actually clicked. The only way I understand this is possible if in a separate thread hidden from the user such as the  <strong>Event Dispatching Thread</strong> there is a constant polling every so often, maybe every few milliseconds to check to see if it was clicked. On top of this, how does a button click invoke code?</p>
  
  <p>I assume people are going to suggest it is the <strong>Observer Pattern</strong> at work here, but from the examples I have seen, the user more or less explicitly notifies the observers so it's almost no different than calling just a regular method.</p>
  
  <pre><code>s.setName("IceCream");
  public void setName(String name) {
      this.name = name;
      setChanged();
      notifyObservers();
  }
  </code></pre>
  
  <p>and then the update() method is called. This isn't the Observer Pattern from scratch but using the Observable and Observer classes.</p>
  
  <p>Let me know if anything needs to be clarified</p>
  
  <p>This question is sort-of-similar to my last question regarding how to constantly poll a condition without busy waiting. <a href="https://stackoverflow.com/questions/45000556/how-do-you-pause-a-thread-until-a-condition-becomes-true-without-busy-waiting/45000636#45000636">How do you pause a thread until a condition becomes true without busy waiting?</a></p>