0

Hello

I have this NetBeans project to complete and im having a problem passing text from a Jtextfield to another JFrame. I just need to get the data to that JFrame to use an SQL.

Please help me

Kind regards,
Java newbie

2
Contributors
4
Replies
8
Views
7 Years
Discussion Span
Last Post by deiago
0

One way is to add a method in the class with the data that will return the data.
Then pass a reference to that class to the class that needs the data where it can be called.
In the class with the textfield: tf
public String getData() [
return tf.getText();
}

In the class that wants the data;
String data = refToClassWithData.getData();

0

@ NormR1
Thank you for your reply! :)

I'm trying that... but Im getting an error ( Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" ) when i try to convert "ID" to an integer ( reason is ID is stored as in integer in my database and its stored as a String in the texfield)....

any help>??

0

What is the contents of the String you are trying to convert?
Your comment shows "ID" as the String. That's not an integer!
What method are you using to convert the String to an int?

0

I have solved it! :) Turns out the data was not being stored in the variable when I entered the new JFrame, so I made it static and passed the static variable :) worked beautifully :)

Keep up the great work :)
Thanks @NormR1
Kind regards,
Deiago

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.