PDA

View Full Version : [SOLVED] taking input from java interface



vineeth v s
September 6th, 2011, 06:06 PM
hi,

i am now working on a project which uses java to make am applet interface
and take inputs and updates a database.Leave the database part,can anyone tell me
how to take inputs from java interface, both string and integer?? or it is enough top point me some
tutorials or links ....
it ll be a great help,

thanks in advance,....:popcorn:

PaulM1985
September 6th, 2011, 06:31 PM
Could you be a little clearer on what you are struggling with? Have you created a user interface already?

To make it very simple, you could just have two JTextFields on your applet, one for the String, one for the Integer as well as a button that would say "Submit" or something similar.

In the code for the Submit button, you would get the text from the JTextField for the String and for the integer, you would get the text from the JTextField and then use Integer.parseInt(integerString) to parse it to an integer. (Once you have done this you can add safety code to prevent people putting silly inputs).

Paul

vineeth v s
September 6th, 2011, 06:42 PM
ooppss.. sory for my english... :D

yes, your answer will help...

but all i was trying to do is to take a string from JText field and
store it to a variable in the program . is it possible?? is their some function for it??

ofnuts
September 6th, 2011, 06:44 PM
Could you be a little clearer on what you are struggling with? Have you created a user interface already?

To make it very simple, you could just have two JTextFields on your applet, one for the String, one for the Integer as well as a button that would say "Submit" or something similar.

In the code for the Submit button, you would get the text from the JTextField for the String and for the integer, you would get the text from the JTextField and then use Integer.parseInt(integerString) to parse it to an integer. (Once you have done this you can add safety code to prevent people putting silly inputs).

PaulIt would be better to use a NumberFormat to parse the number. Does some of the sanity checks, and will handle necessary cultural variations (1000,000 and 1000.000 aren't the same across the Atlantic...)

myrtle1908
September 7th, 2011, 02:58 AM
but all i was trying to do is to take a string from JText field and
store it to a variable in the program . is it possible?? is their some function for it??

JTextField has a getText() method.

http://download.oracle.com/javase/tutorial/uiswing/components/textfield.html

cgroza
September 7th, 2011, 03:15 AM
JTextField has a getText() method.

http://download.oracle.com/javase/tutorial/uiswing/components/textfield.html
Use that combined with Int.parseInt() and you get the result you want.

vineeth v s
September 7th, 2011, 06:22 AM
oh!! man.. this is exactly wat i want.... thnku guyss....:popcorn::guitar: