Jump to content

Java JTextField array error checking

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Disco

Disco

    Newbie

  • Members
  • Pip
  • 2 posts
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 :

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
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
You should just use the logical not operator ( ! ), and apply it to see if text[a] is equal to "X".
if (!text[a].getText().equals("X"))
{
    JOptionPane.showMessageDialog(nu..., "Must use X only.");
}

Wow I changed my sig!

#3
Disco

Disco

    Newbie

  • Members
  • Pip
  • 2 posts
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

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
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!