title: How can I automate the response on a Swing Dialog Box?
body: <p>Given the simplest code possible:</p>
  
  <pre><code>//getDialogResponse() cannot be changed.
  public static int getDialogResponse() {
      return JOptionPane.showConfirmDialog(null, "Make a really important choice.", "THE CHOICE", JOptionPane.YES_NO_CANCEL_OPTION);
  }
  
  public static void main(String[] args) {
      int[] val = new int[1];
      SwingUtilities.invokeLater(() -&gt; {val[0] = getDialogResponse();});
      //TODO: The program itself presses the 'Yes' button.
      if(val[0] == JOptionPane.YES_OPTION) System.out.println("Good Choice.");
      else System.out.println("Wise guy, huh?!");
  }
  </code></pre>
  
  <p><code>Robot</code> seems like a poor fit, since it needs to know the location of the newly created dialog box, and if it isn't in the same location every time, it won't work, so I need to know either how to get the location of the button itself, or I need to know a method that doesn't depend on the position of the newly created dialog box.</p>
  
  <p>Also, I cannot change the <code>getDialogResponse()</code> code: that's an invariant.</p>
  
  <p>So what can I do?</p>