Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please can someone explain how I can take user input and pass it to another vairable?  RSS feed

 
drew taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please can you help me with the following?

I have created a JOption pane that has an input box and a button using the following code:

String add = JOptionPane.showInputDialog(null, "enter website address: ");
System.out.print(add);


How would I take the user input and put it into a variable. I just need to put it into a variable which I can then use later. Any help you can give will be appresiated!

Thanks,

Drew,
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user input is in a variable. The name of that variable is "add".
 
drew taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to allow the user to specify a URL, click the button and assign the add variable to a URL variable.

URL url = new URL("http://url");

Would this work?

String URLInput = JOptionPane.showInputDialog(null, "Please enter a URL: ");
System.out.print(URLInput);


URL url = new URL(URLInput);

[ October 01, 2007: Message edited by: drew taylor ]
[ October 01, 2007: Message edited by: drew taylor ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by drew taylor:
I want to allow the user to specify a URL, click the button and assign the add vairable to a URL variable which was made by

URL url = new URL("http://url");

Would this work?

URL url = new URL(add);


Does it? Have you tried it? What happened?
 
drew taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it worked! ;-)
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by drew taylor:
Yes it worked! ;-)


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!