« Return to Thread: no "Friend"s in Java

Re: no "Friend"s in Java

by Matthew Lengenfelder :: Rate this Message:

Reply to Author | View in Thread

tyvm :)

Matt Lengenfelder


On Thu, May 8, 2008 at 1:34 AM, Sean Carrick <seansitsolutions@...> wrote:
One way to do it, that I use often, is to create a null object of the D1View in the class you need to be able to change the JTextArea1 text from:

public class MyClass {
  private D1View frmD1View;

Then, in the MyClass constructor, accept a parameter of type D1View and create an instance of MyClass in your D1View object.

public class D1View extends JFrame {
  private MyClass myClass;

  public D1View() {
     initComponents();
       myClass = new MyClass(this);
       ...
  } // End of D1View constructor.
} // End of D1View frame.

public class MyClass {
     private D1View frmD1View;
       public MyClass ( D1View view) {
        this.frmD1View = view;
     } // end of MyClass constructor.

     private void someFunction () {
        this.frmD1View.append ( "XYZ" );
     } // end of someFunction().
} // End of MyClass.

This basically creates a "pointer" to the current instance of D1View that is in operation, since your MyClass constructor was called with "this" from the D1View constructor.

--

Cheers,

Sean Carrick
PekinSOFT Systems
sean@...
http://www.pekinsoft.net

----------------------------------
Proud to be 100% Microsoft free...
----------------------------------


 « Return to Thread: no "Friend"s in Java