2
I made a Celsius temperature converter for Fahrenheit, I’m willing to treat if in JTextField
is different from 0, display the temperature in Fahrenheit, but appears 0.0 until empty, with spaces inserted in that field.
@Override
public void actionPerformed(ActionEvent e) {
double resultado = 0, valor1;
if(e.getSource() == btnOk) {
if(!text1.getText().isEmpty()) {
try {
valor1 = Double.parseDouble(text1.getText());
resultado = valor1 * 1.8 + 32;
}catch(NumberFormatException e1) {}
text2.setText(String.valueOf(resultado));
}
}
What is the use here || fieldText.equals("0") ?
– user67285
@user67285 validation is not empty and be non-zero ne? this is valid if the reported value is zero. I made a correction, it should be different from zero.
– user28595
It was just the spaces.
– user67285
@user67285 good, then I have sinned by the excess :D just remove this validation that will work right.
– user28595