Closed Thread
Results 1 to 4 of 4

Thread: Java JTextField array error checking

  1. #1
    Disco is offline Newbie
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Java JTextField array error checking

    Hi lads,

    Just wondering how I can take in the text from an array of JTextFields and check to see if their values are not = to "X" .

    So far my code is :

    Code:
    public void actionPerformed(ActionEvent e) {
    
    if(e.getActionCommand().equals("nextP…
    count++;
    if(count == 1 || count == 3 || count == 5 || count == 7 || count == 9){
    while (a<b){
    if(text[a].getText() != "X"){
    JOptionPane.showMessageDialog(nu… "Must use X only");
    
    }
    
    }
    
    }
    nextPlayer is a button
    and the while a<b is just a loop to go through the array of text fields called text[]

    Thanks,
    Disco

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Java JTextField array error checking

    You should just use the logical not operator ( ! ), and apply it to see if text[a] is equal to "X".
    Code:
    if (!text[a].getText().equals("X"))
    {
        JOptionPane.showMessageDialog(nu..., "Must use X only.");
    }
    Wow I changed my sig!

  4. #3
    Disco is offline Newbie
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Re: Java JTextField array error checking

    Thanks for your reply mate , but its still accepting letters that are not X . Any other ideas... This stuff is stressing me out at this stage ...

    Thanks,
    Disco

  5. #4
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Java JTextField array error checking

    Is it showing the JOptionPane properly? That's all that program should do, show a JOptionPane, since it's not sending any "rejection" code or performing any other action that would cause the user to be unable to input anything other than X. I think you're the only one who can pull that off since you know your code better than I.

    If you have the code that executes by pressing the button after this loop and you don't want that code to execute, you just need to return; there.
    Wow I changed my sig!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error in checking for duplicate strings?
    By surwassu in forum C and C++
    Replies: 2
    Last Post: 07-15-2011, 09:37 AM
  2. MASM Error checking help
    By Slider in forum Assembly
    Replies: 6
    Last Post: 01-26-2011, 11:03 AM
  3. Disable error checking in c++
    By lysergicc in forum C and C++
    Replies: 5
    Last Post: 11-06-2010, 12:04 PM
  4. Error checking issues
    By mistymoon1966 in forum C and C++
    Replies: 2
    Last Post: 11-09-2009, 07:14 AM
  5. C error checking problem
    By s0n1c in forum C and C++
    Replies: 5
    Last Post: 02-05-2008, 07:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts