Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does an object pass itself as a parameter?

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.

like image 829
Renato Dinhani Avatar asked Nov 27 '22 12:11

Renato Dinhani


1 Answers

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

}
like image 92
blank Avatar answered Nov 30 '22 01:11

blank