About pop-up dialog box, JOptionPane;

Hi,

I'm new to this and hope someone could help me. :) I made a pop-up window. If I press the 'OK' button without entering anything, the sketch window will get stuck. I have to press the 'RUN' button to run it again. But I need it to be that if I press the 'OK' button without entering anything, there will be no change. Is that possible?

Thanks in advance!

Answers

  • Answer ✓

    Is that possible?

    I dn't see why not it depends on you what you do with the information from the dialog box. In other words the reason the sketch gets stuck is almost certainly to do with your code. Perhaps you can post a simple code example demonstrating the problem.

  • edited May 2015 Answer ✓

    it is hard to tell

    • does the code crash? do you get an error message? in the ide?

    • which one?

    when you are receiving a String from the pop up and you use it and it is empty this can happen

    try check it before using it:

    if (stringFromPopUp!=null && !stringFromPopUp.equals("")) {
        // good
    }
    

    ;-)

  • I think I found the problem. I want it to show the first letter of what I put in the dialog box. So I writed: text(newS.charAt(0),mouseX,mouseY); However if I enter nothing in the dialog box, there is no newS.charAt(0). How can I solve this problem? Thanks

  • edited May 2015 Answer ✓

    solve it with what I just posted

    e.g. when it's empty give it the value "x"

    then use text(newS.charAt(0),mouseX,mouseY);

  • I've solved it. Thank you guys!!:D

  • great!

Sign In or Register to comment.