Simply use:
int ans = Integer.parseInt( JOptionPane.showInputDialog(frame,
"Text",
JOptionPane.INFORMATION_MESSAGE,
null,
null,
"[sample text to help input]"));
You cannot cast a String
to an int
, but you can convert it using Integer.parseInt(string)
.