codice:
int valoreDimensione = 0;
try {
   valoreDimensione = Integer.parseInt(dimensione.getText());
} catch(NumberFormatException e) {
   JOptionPane.showMessageDialog(null,"Devi inserire un intero", 
      "Attenzione",JOptionPane.INFORMATION_MESSAGE);
}