Member Avatar for deiago

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

Recommended Answers

All 4 Replies

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();

Member Avatar for deiago

@ 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>??

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?

Member Avatar for deiago

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.