package example6_2; import javax.swing.JOptionPane; public class JOptionPaneRelief { public static void main(String[] args) { // REPLACE THIS PART WITH Double.parseDouble() // and try/catch // No need to loop. // You can just catch "Exception" String defaultMessage = "How many kg of food?"; String updatedMessage = defaultMessage; double foodKg = -1; while(foodKg <= 0) { // until: input valid: foodKg > 0 String line = JOptionPane.showInputDialog(updatedMessage); try { foodKg = Double.parseDouble(line); } catch(Throwable e) { // } catch(Exception e) { // alternative updatedMessage = defaultMessage + " Please enter a number (may have decimal part)"; } } System.out.println("You entered:"+foodKg); } }