Using Robot to test an InputDialog

Hi experts,
I am a java newbie and I'm trying to use the Robot class to test an InputDialog. The problem I run into is when I call the .showInputDialog the dialog box waits for a click on the ok or cancel button from me and doesnt get to the code i've written for the Robot in my test. Is there a way to get around this? If so may i see some sample code. Thanks in advance. Here is the code I have...
public class testMaxWidthDialog extends TestCase
      public void testDialog() throws AWTException
            JMaxWidth test = new JMaxWidth();
            Robot r2d2 = new Robot();
//and the class
public class JMaxWidth extends JPanel
      protected String input;
      public JMaxWidth() throws AWTException
                      input = JOptionPane.showInputDialog(null, "Enter maximum width.");
Who is Participating?
CI-Ia0sConnect With a Mentor Commented:
Thread roboCodeThread = new Thread(new Runnable(){
public void run(){
//Call to method with robo code you want executed

After the roboCodeThread, put your dialog box and you're set to go. Out of curiosity, why do you want the box to pop up while the robo code is running? If you need the data from this box for any of the robo code execution stuff, wouldn't it be better to get the data first? Or, if you don't need the data for the robo code, wouldn't it be better to get it when you do need it?

input = JOptionPane.showInputDialog(null, "Enter maximum width.");
doesn't need the "null."
gfaceAuthor Commented:
Thank you for the reply. I wanted to get in touch with you to let you know I got ypur response. I probably won't be able to test the code until later though. This is for a test driven development class in college and I have to write a test that will pass for all the classes / methods I write. Thats why i need to have the dialog pop up and simulate the data entry with the robot running. Its proven to be kinda frustrating because I know the code will pass if I click on it with the mouse but I need a test to prove it. Eventually I will need to retrieve the data from the dialog box but that will be another test. Gotta get past this one first. :). Be in touch soon.
Glad to help. :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.