« Return to Thread: no "Friend"s in Java
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
| Free Forum Powered by Nabble | Forum Help |