Results 1 to 9 of 9
- 10-03-2009, 12:20 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 18
- Rep Power
- 0
change value in the in the creator class
How do i change value in the creator class
for example:
public class A {
private int num = 0;
private B b;
public A(){
b = new B();
System.out.println(num);
}
public void changeInt(int newNum){
num = newNum;
}
public static void main(String[] args) {
A a = new A();
}
}
public class B {
public B(){
A.this.changeInt(5); <-------- Error
}
}
Error: No enclosing instance of the type A is accessible in scope
thanksLast edited by livnihai; 10-03-2009 at 01:29 PM.
- 10-03-2009, 01:43 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Read the classes section of Sun's tutorial.
That line doesn't make any sense.
creates an A.Java Code:A a = new A();
changes the value.Java Code:a.changeInt(5);
- 10-03-2009, 02:21 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 18
- Rep Power
- 0
ok,
i'll explain my problem.
I've created a class that listen to event, i need that when the
event happen the main class sould know about that.
I don't want to ask over and over from the main class
The question is, how do i comunicate back from the secondery class
to the main class
thanks
-
- 10-03-2009, 05:39 PM #5
Member
- Join Date
- Sep 2009
- Posts
- 18
- Rep Power
- 0
Isn't there a direct way to do it without third party ?
-
- 10-06-2009, 03:08 PM #7
Member
- Join Date
- Sep 2009
- Posts
- 18
- Rep Power
- 0
Any help how to implement Observer pattern
maybe a simple tutorial
thanks
- 10-06-2009, 03:22 PM #8
Go thru this article.Really ,it is simple and good.
Abhi On Java: Implementing Observer Pattern in JavaRamya:cool:
- 10-07-2009, 06:14 AM #9
Member
- Join Date
- Sep 2009
- Posts
- 18
- Rep Power
- 0
How do i use observer pattern on this simple example:
[code]
public class A {
private int num = 0;
private B b;
public A(){
b = new B();
System.out.println(num);
}
public static void main(String[] args) {
A a = new A();
}
}
public class B {
private int num;
public B(){
num = 10;
}
}
I need that class A will print 10
thanks
Similar Threads
-
can we change label from action class?
By kishan in forum Advanced JavaReplies: 2Last Post: 04-28-2009, 02:12 PM -
Gui Swing Creator
By 2o2 in forum New To JavaReplies: 4Last Post: 10-01-2008, 11:38 PM -
How to use TextAttribute class to change color and font of a text
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:33 AM -
Java Studio Creator - Bd Alterar
By wagnerbarbos in forum JCreatorReplies: 0Last Post: 06-09-2008, 05:19 PM -
Cast Error Caught (change) Class is really: java.lang.String
By barney in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 04:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks