M
Maurizio
Hi to all,
I've some problem with Observer/Observable object model.
I've found this interesting article:
http://www.javaworld.com/javaworld/javatips/jw-javatip29.html
I've try this simple program based on the instruction, but I can't get
DisplayObserver on my console.
Could you give me some suggestion
thank you very very much!
Regards
Maurizio
*******************************
*** FILE main.java ***
*******************************
public class main {
public static void main(String[] args) throws NumberFormatException,
IOException {
MsgObservable msgObj = new MsgObservable();
DisplayObserver display = new DisplayObserver();
msgObj.addObserver( display );
msgObj.test();
System.out.println("END");
*******************************
*** FILE MsgObservable.java ***
*******************************
import java.util.Observable;
public class MsgObservable extends Observable
{
public MsgObservable(){}
public void test()
{
Object msg = new Object();
notifyObservers( msg );
}
}
*********************************
*** FILE DisplayObserver.java ***
*********************************
import java.util.Observable;
import java.util.Observer;
public class DisplayObserver implements Observer
{
public DisplayObserver(){}
public void update( Observable obj, Object arg )
{
System.out.println("DisplayObserver");
}
}
I've some problem with Observer/Observable object model.
I've found this interesting article:
http://www.javaworld.com/javaworld/javatips/jw-javatip29.html
I've try this simple program based on the instruction, but I can't get
DisplayObserver on my console.
Could you give me some suggestion
thank you very very much!
Regards
Maurizio
*******************************
*** FILE main.java ***
*******************************
public class main {
public static void main(String[] args) throws NumberFormatException,
IOException {
MsgObservable msgObj = new MsgObservable();
DisplayObserver display = new DisplayObserver();
msgObj.addObserver( display );
msgObj.test();
System.out.println("END");
*******************************
*** FILE MsgObservable.java ***
*******************************
import java.util.Observable;
public class MsgObservable extends Observable
{
public MsgObservable(){}
public void test()
{
Object msg = new Object();
notifyObservers( msg );
}
}
*********************************
*** FILE DisplayObserver.java ***
*********************************
import java.util.Observable;
import java.util.Observer;
public class DisplayObserver implements Observer
{
public DisplayObserver(){}
public void update( Observable obj, Object arg )
{
System.out.println("DisplayObserver");
}
}