Thread: Compile Trouble
View Single Post
  #6 (permalink)  
Old 04-21-2008, 03:02 AM
bobleny's Avatar
bobleny bobleny is offline
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
Simple, you use the Integer.parseInt() method.
Code:
String stroption = JOptionPane.showInputDialog(null, menu, "Choose an Option:", JOptionPane.QUESTION_MESSAGE); int option = Integer.parseInt(stroption);
If you really want to get fancy to avoid any error, use a try catch statement:
Code:
String stroption = JOptionPane.showInputDialog(null, menu, "Choose an Option:", JOptionPane.QUESTION_MESSAGE); int option; try { option = Integer.parseInt(stroption); } catch(Exception E) { option = 0; }
And life is good....
__________________
--
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
--
Cheer up, the worst has yet to come...
Reply With Quote