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

RE: no "Friend"s in Java

by Gary Greenberg-4 :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

you do need a default constructor in your D1View class.

I presumed you had one.

 

From: Matthew Lengenfelder [mailto:matt.lengenfelder@...]
Sent: Wednesday, May 07, 2008 9:54 PM
To: nbusers@...
Subject: Re: [nbusers] no "Friend"s in Java

 

My NewClass file:
--------------------------
package d1;

public class NewClass {   
    public void test(){
        D1View myView = new D1View();
        myView.jTextArea1.append("XYZ");
    }
}

The error I get running the application:
-----------------------------
init:
deps-jar:
Compiling 1 source file to C:\programs\java\D1\build\classes
C:\programs\java\D1\src\d1\NewClass.java:5: cannot find symbol
symbol  : constructor D1View()
location: class d1.D1View
        D1View myView = new D1View();
1 error
BUILD FAILED (total time: 0 seconds)

I guess I just havn't used Gui builders enough, wouldn't that create a new object/form? I don't want a new form I want to be able to change the existing one.


On Wed, May 7, 2008 at 11:16 PM, Gary Greenberg <gary.greenberg@...> wrote:

What do you mean "can't be called"? It can and will.

How do you call it?

If write following two lines:

 

D1View myView = new D1View();

myView.setText("XYZ");

 

It will do what you want.

 

Friend modifier in C++ is an abomination.

 

From: Matthew Lengenfelder [mailto:matt.lengenfelder@...]
Sent: Wednesday, May 07, 2008 8:37 PM
To: nbusers@...
Subject: [nbusers] no "Friend"s in Java

 

I'm started to do some java programming in netbeans and thought I'd toss this out there.

simple example:
create a new project - Java Desktop Application, basic application "D1"
on "D1View" drop some controls in the design view,
create a new java class
create a function in that class and try to connect to any of the controls you created in the D1View class
for instance you can't set the value of JTextArea1

I've tried making a new function for instance

    public void setText(String test) { jTextArea1.append(test); }

in the D1View class that takes a string and appends JTextArea1 and it works but that function also can't be called outside of the class...

There is no way to set "Friend" classes in Java.

public class D1View
 - this is how the class is declared, so it's public and my simple setText function is public, why in the world will it not let me access it in another class, in the same package?

if I set "setText" to be static then other classes can see it, but it won't compile while accepting a string.

I've also gone through the designer and used custom code to set both JTextArea1 and the mainPanel to be public in the hopes that something would show up as usable in the NewClass but so far nothing is.

Thoughts?

Matt Lengenfelder

 

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