Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

help with JOptionpane

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int anInt = Integer.parseInt(guess);

(but you will need to combine it with some error-handling)
 
Adam C.
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


something like that, or am i way off?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by int i mean a number input by a person
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would you like any further responses posted here, or at sun?

http://forum.java.sun.com/thread.jspa?threadID=658834
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Adam C.
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic