please help regarding focus


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: please help regarding focus

  1. #1
    Join Date
    Jul 2007
    Posts
    7

    please help regarding focus

    Hello2


    catch (NumberFormatException error) // catch to identify if integers were not inputs in JTextFields
    {
    // give an error box if periodicPayment, interest, compunds, and years have String inputs
    JOptionPane.showMessageDialog( this,
    "Please enter numbers for Periodic Payment and Interest,\n" +
    "and integers for Compounds per Year and Years. Try again!",
    "Input Error", JOptionPane.ERROR_MESSAGE );

    // transfer focus
    periodicPaymentJTextField.requestFocusInWindow();

    } // end catch


    My question is:

    How to make the focus on the place where we have wrong problems? I want to use if, else statement, but, in this case, how to validate string inputs?

    THANK YOU

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I am uncertain about what you mean by your use of the word "focus". I imagine that the erroneously formatted data would not be added to your storage container because of the exception. I am not sure if you are using focus in the "GUI focus" - "active window" - manner, or just "calling attention to the input which generated the exception". I proceed with the second in mind.

    The key to your approach to validation lies where your exception is being generated.

    I expect that you have assigned the input to some temporary variable(s). As long as you have not deleted or overwritten those variables (or they have not gone out of scope) you can still evaluate them.

    Do your validation on the values stored in these variables - use a "Pattern" and "Matcher" to test whether this validates [see the Regex materials]. OR, if it is as easy as the input string cannot evaluate to a number because of the presence of a non-number character, your test is straightforward. Just display the user's erroneous input back to him/her and ask the user to re-enter the input in the correct format.

Similar Threads

  1. Poup and Steal Focus
    By Dean Earley in forum VB Classic
    Replies: 4
    Last Post: 05-02-2001, 12:45 PM
  2. focus() & select() not working
    By Craig in forum Web
    Replies: 7
    Last Post: 02-08-2001, 02:16 PM
  3. Determining focus
    By Bob Rouse in forum VB Classic
    Replies: 6
    Last Post: 12-14-2000, 12:02 PM
  4. Determining focus
    By Bob Rouse in forum VB Classic
    Replies: 0
    Last Post: 12-13-2000, 11:43 AM
  5. Replies: 0
    Last Post: 12-01-2000, 05:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center