Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes help with JOptionpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with JOptionpane" Watch "help with JOptionpane" New topic
Author

help with JOptionpane

Adam C.
Greenhorn

Joined: Aug 30, 2005
Posts: 4
how would i get JOptionpane to change an int variable when a number is input?



how would i get those two to communicate?
trying number= gives me a required int error

[ August 31, 2005: Message edited by: Adam C. ]
[ August 31, 2005: Message edited by: Adam C. ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
int anInt = Integer.parseInt(guess);

(but you will need to combine it with some error-handling)
Adam C.
Greenhorn

Joined: Aug 30, 2005
Posts: 4


something like that, or am i way off?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
showInputDialog(..) returns a String
Integer.parseInt(String arg) takes a String as an argument and returns an int

try re-working your posted code
(taking a closer look at your original and my original posts)
Atrus Greyor
Ranch Hand

Joined: Mar 07, 2004
Posts: 110
May as well warn you now, your name doesn't fit the naming policy. In other words you need to have a full last name, not an inital!

And on your code, the whole putting an int to an optionPane just doesn't seem right to me, but I'm not very experenced and it may be perfectly fine. Sorry I'm not of much help there!
[ August 31, 2005: Message edited by: Atrus Greyor ]
Adam C.
Greenhorn

Joined: Aug 30, 2005
Posts: 4
by int i mean a number input by a person
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
would you like any further responses posted here, or at sun?

http://forum.java.sun.com/thread.jspa?threadID=658834
Daniel .J.Hyslop
Ranch Hand

Joined: May 23, 2005
Posts: 55
Hi adam,
These two links will take you to the two packages that contain the classes that you need to consider Class JOptionPane with showinputDialog method that returns a String , even though you are typing in a number at JOptionPane it is still recognised as a string ,it must be parsed .Thejava lang package (which is imported implicitly) which contains the class, which contains the methods for changing your String input into an int

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/package-summary.html
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/package-summary.html
[ August 31, 2005: Message edited by: Daniel .J.Hyslop ]

an island in the sun <br />with a language of many tongue?
Adam C.
Greenhorn

Joined: Aug 30, 2005
Posts: 4
thank you all for your help, i finally got it completely working


almost the whole time i was just missing the number=(int) typecast
[ August 31, 2005: Message edited by: Adam C. ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Adam C.:
almost the whole time i was just missing the number=(int) typecast


Actually the cast shouldn't be necessary, as parseInt already returns an int, doesn't it?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
 
subject: help with JOptionpane