• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

pass data from one class to another in java

toughwimp11

Senior member
This seems like it should be really simple and maybe it is and I'm just not seeing it.
Anyway, in netbeans, i created a simple project with a main.java. I then created a jframe which created a jframe class which has a jtable in it. Now, I want to fill the jtable in with values from a data structure i've established in main.java but i can't figure out how to pass the values on.

from my static void main() method in main.java, i can call cFrame.main(null) to bring up the jframe but if i try to pass any data that is not static, it gives me an error, any suggestions?

Edit:
to clarify, i have two classes, main.java and cFrame.java and i want to pass a variable from main to cFrame
 
Last edited:
Are you familiar with OOP at all? If so nickbits solution should make sense, otherwise I'd recommend getting a book on java that covers the principals of OOP.
 
yes, i got it. netbeans creates new jframe classes with a main which i didnt really understand why but i used it which caused a problem because I couldn't start the jframe from the main of the jframe class because it's static. anyway, deleting the main method from the jframe class solved the problem. thanks though!
 
yes, i got it. netbeans creates new jframe classes with a main which i didnt really understand why but i used it which caused a problem because I couldn't start the jframe from the main of the jframe class because it's static. anyway, deleting the main method from the jframe class solved the problem. thanks though!

you really need to get some OOP basics. Next time you won't be so lucky.

Even if some class has static function, you don't have to use it. Classes are meant to be used as objects, declared using constructors.
 
Back
Top