I have a JFrame that is the main class of the program. I want to pass him itself to another two classes, one that will update some label with statistics and another that will validate a lot of fields.
I done the getters to these fields, but how I do to the JFrame pass itself to these classes to they can do their work?
EDIT: My error, my fault. The first thing I done is the this
method. Yes, this
solves my problem, but it did not realize that I was making a mistake.
I was doing this: new Statistics().execute(this);
where the right thing is this: new Statistics(this).execute();
Only with all the answers saying the same thing I realized that I was doing a stupid thing. Thanks to all.
Just pass a reference to this
public class Other {
public void doSomething(JFrame jFrame) {
...
}
}
public class MyFrame extends JFrame {
Other other = new Other();
public void method() {
other.doSomething(this);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With