I made a temperature converter from Celsius to Fahrenheit, I'm trying to treat if the JTextField
is different from 0, display the temperature in fahrenheit, but 0.0 appears 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));
}
}