pass data from one class to another in java

toughwimp11

Senior member
May 8, 2005
415
0
76
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:

ObscureCaucasian

Diamond Member
Jul 23, 2006
3,934
0
0
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.
 

toughwimp11

Senior member
May 8, 2005
415
0
76
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!
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
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.