i have an api that have 3 textfields:
name: (gere goes textfiel1)
Last Name: (Second textfiel)
Id: (number 3 textfield)
then i have a button named SAVE , wen i hit SAVE all 3 textfields info goes to a txt.
Now the thing is that i want to control what people may put in the field i mean i dont want to save in the name textfield a number you know so i got the following code and i think i need to order this properly so this could work:
String line="";
String errorMsg = "";
boolean error = false;
int ci = 0;
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if (jTextField1.getText().length() == 0 || jTextField1.getText().trim().length() == 0){
error = true;
errorMsg = "Must put a name ";
}else if (jTextField2.getText().length() == 0 || jTextField2.getText().trim().length() == 0){
error = true;
errorMsg = "Must put a last name ";
}else if (jTextField3.getText().length() == 0 || jTextField3.getText().trim().length() == 0){
error = true;
errorMsg = "Must put an ID ";
}else{
try{
ci = Integer.parseInt(jTextField3.getText());
}catch(NumberFormatException ne){
error = true;
errorMsg = "The ID must be numeric.";
}
}if(error){
JOptionPane.showMessageDialog(this, errorMsg, "Error ", JOptionPane.ERROR_MESSAGE);
}
String line= jTextField1.getText()+" "+jTextField2.getText()+" "+ jTextField3.getText()+"\n" ;
try{ //This part works fine
FileWriter fw= new FileWriter("C:\\Grupo.txt", rootPaneCheckingEnabled);
fw.write(line);
fw.close();
}catch(IOException e){};
}
Thank you ranchers !!