I'm blocked and I do not know how to move forward.
I have the following information:
String Equiv1="";
String Equiv2="";
String equivalencia1="";
public int probarEquiv1 (){
Equiv1 =ConversorNou.PrimeraDivisaTXT.getText();
Equiv2 = ConversorNou.SegundaDivisaTXT.getText();
equivalencia1 = ConversorNou.EquivalenciaTXT.getText();
And I have to check them one by one.
That is:
1- Verify that Equiv1 is "Dollar", "Euro", "weight" if it is correct to proceed to the next verification.
2- Check Equiv2: Be "dollar", Euro, Weight but do not repeat with Equiv1 (ie if Equiv1 is Dollar then Equiv2 can only be Peso or Euro) If it is correct, it will verify the following.
3-Verify that it is Equivalence that must be: Number greater than 0, and can accept decimals.
What is my problem that I know how to verify them all together but not separately.
In the end if the verification of everything is correct they have to go to RETURN 1 if it is incorrect to RETURN 2 (but if the return 2 option comes out that is incorrect I have to know which part of the verification is incorrect)
The problem I have is that I do not know how to do the checks one by one and have the return show what the wrong data is.
If any of the 3 verifications fails, I have to know 100% of them and show it with the setFocus ()
The part of the return is this:
Button botonDadesEntrades = new Button(Conversor_de_divises, SWT.BORDER);
botonDadesEntrades.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (data.probarEquiv1()==1){
JOptionPane.showMessageDialog(null, "Datos Correctos");
}else{
PrimeraDivisaTXT.setFocus(); // asigno el foco al textfield
PrimeraDivisaTXT.selectAll(); // luego selecciono todo el texto
JOptionPane.showMessageDialog(null, "Error has puesto un dato incorrecto "
}
}
});
I need to know how to modify the return part 2 so that it shows what the wrong data is.
Thanks in advance! It involves using the setfocus () setall () to select the wrong one. But I'm blocked .. T_T
thanks!
Edited:
The part to prove Equiv1 that I have done:
if(Equiv1.equalsIgnoreCase("Euro")&& Equiv2.equalsIgnoreCase("Dolar")&& DatosUser.esDecimal1(equivalencia1)){
return 1;
}
else if ( Equiv1.equalsIgnoreCase("Dolar")&& Equiv2.equalsIgnoreCase("Euro")&& DatosUser.isNumeric(equivalencia1)){
return 1;
}
else if ( Equiv1.equalsIgnoreCase("Euro")&& Equiv2.equalsIgnoreCase("Dolar")&& DatosUser.isNumeric(equivalencia1)){
return 1;
}
else if (Equiv1.equalsIgnoreCase("Dolar")&& Equiv2.equalsIgnoreCase("Euro")&& DatosUser.esDecimal1(equivalencia1)){
return 1;
}
else{
return 0;
}
}
private static boolean isNumeric(String cadena){
try {
Integer.parseInt(cadena);
return true;
} catch (NumberFormatException nfe){
return false;
}}
public static boolean esDecimal1(String cad)
{
boolean hayPunto=false;
StringBuffer parteEntera = new StringBuffer();
StringBuffer parteDecimal = new StringBuffer();
int i=0, posicionDelPunto;
for( i=0;i<cad.length(); i++ )
if ( cad.charAt(i) == '.') //Detectar si hay un punto decimal en la cadena
hayPunto=true;
if(hayPunto) //Si hay punto guardar la posicion donde se encuentra el carater punto
posicionDelPunto=cad.indexOf('.'); //(si la cadena tiene varios puntos, detecta donde esta el primero).
else
return false; //Si no hay punto; no es decimal
if( posicionDelPunto == cad.length()-1 || posicionDelPunto== 0) //Si el punto esta al final o al principio no es un decimal
return false;
for( i=0;i<posicionDelPunto; i++ )
parteEntera.append(cad.charAt(i)) ; //Guardar la parte entera en una variable
for(i = 0; i<parteEntera.length(); i++)
if( ! Character.isDigit(parteEntera.charAt(i)) ) //Si alguno de los caracteres de la parte entera no son digitos no es decimal
return false;
for( i=posicionDelPunto+1;i<cad.length(); i++ )
parteDecimal.append(cad.charAt(i)); //Guardar la parte decimal en una variable
for(i = 0; i<parteDecimal.length(); i++)
if( ! Character.isDigit(parteDecimal.charAt(i)) ) //Si alguno de los caracteres de la parte decimal no es un digito no es decimal
return false; //Incluye el caso en el que la cadena tenga dos o mas puntos
return true; //Si paso todas las pruebas anteriores, la cadena es un Numero decimal
}
public boolean esDecimal(String cad)
{
try
{
Double.parseDouble(cad);
return true;
}
catch(NumberFormatException nfe)
{
return false;
}
}
}