Hi All,
I am having a bit of an issue moving back into Java.
The issue that I am having is that I am trying to call a method of a custom class that has been instantiated in my main java file from a form that is also in an external file.
The purpose for this is so that I can have an event triggered on the form when a button is pressed to run my method from my default class.
Am I out to lunch?
Should I just instantiate my class in the form class?
Thanks,
corliss
corliss
0
Newbie Poster
Recommended Answers
Jump to PostOr you could just pass a reference of the Object to the Form class and store it there and use it when required...
Jump to PostPls tell us what is ur exact mean?
Jump to PostFotsung,
I'm assuming that you mean main class by "form" class.
When you are anywhere in the main class, like the event method, you construct another class in your package like so:
…OtherClass anyName = new OtherClass(); //OtherClass being the name of your other class
Jump to PostThis is a standard problem with a standard solution:
Change the NewJFrame constructor to take an instance of Watcher as a parameter and store it. So your main now looks like…Watcher beholder = new Watcher(); NewJFrame GUI = new NewJFrame(beholder); // pass Watcher instance to GUI
All 14 Replies
stevanity
4
Posting Whiz in Training
fotsung
0
Newbie Poster
StephNicolaou
32
Posting Whiz in Training
corliss
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
corliss
0
Newbie Poster
StephNicolaou
32
Posting Whiz in Training
stevanity
4
Posting Whiz in Training
corliss
0
Newbie Poster
stevanity
4
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
StephNicolaou
32
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
StephNicolaou
32
Posting Whiz in Training
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.