JOptionePane

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Broke
    New Member
    • Mar 2007
    • 7

    #1

    JOptionePane

    hi, i have problem with JOptionPane message, my application is a dictionary, if the user entered invalid word and clicked on search button, warnning message should be displayed. However, in my case the program stick without getting any message.this the code that i wrote:

    //click on the search button
    private void jButton1ActionP erformed(Action Event evt) {
    String key = jTextField1.get Text();
    boolean done = false;
    while(!done){
    try{

    jTextArea3.setT ext(opr.getCode (key));
    jTextArea1.setT ext(opr.getExp( key));

    if(jTextField1. getText()!= key || jTextField1.get Text()== null)
    done = true;
    }

    catch(Exception ex){
    JOptionPane.sho wMessageDialog( null, "Invalid termonology was entered");
    done = false;
    }}}
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by Broke
    hi, i have problem with JOptionPane message, my application is a dictionary, if the user entered invalid word and clicked on search button, warnning message should be displayed. However, in my case the program stick without getting any message.this the code that i wrote:

    //click on the search button
    private void jButton1ActionP erformed(Action Event evt) {
    String key = jTextField1.get Text();
    boolean done = false;
    while(!done){
    try{

    jTextArea3.setT ext(opr.getCode (key));
    jTextArea1.setT ext(opr.getExp( key));

    if(jTextField1. getText()!= key || jTextField1.get Text()== null)
    done = true;
    }

    catch(Exception ex){
    JOptionPane.sho wMessageDialog( null, "Invalid termonology was entered");
    done = false;
    }}}

    For some reason this code does not seem right
    if(jTextField1. getText()!= key || jTextField1.get Text()== null)
    done = true;
    }
    what are you comparing TextField1 with?

    Not sure but might want to use contains() method.
    or equals() method

    nomad

    Comment

    • rsrinivasan
      New Member
      • Mar 2007
      • 221

      #3
      Originally posted by Broke
      hi, i have problem with JOptionPane message, my application is a dictionary, if the user entered invalid word and clicked on search button, warnning message should be displayed. However, in my case the program stick without getting any message.this the code that i wrote:

      //click on the search button
      private void jButton1ActionP erformed(Action Event evt) {
      String key = jTextField1.get Text();
      boolean done = false;
      while(!done){
      try{

      jTextArea3.setT ext(opr.getCode (key));
      jTextArea1.setT ext(opr.getExp( key));

      if(jTextField1. getText()!= key || jTextField1.get Text()== null)
      done = true;
      }

      catch(Exception ex){
      JOptionPane.sho wMessageDialog( null, "Invalid termonology was entered");
      done = false;
      }}}
      Hi,
      I cant understand clearly. The catch block will be executed when you have any run time error in try block. I feel there is no error in try block. If you want to display any msg, put the messagebox in try block.

      Thanks,

      Comment

      Working...