Say there are two classes A , B and class B has a button object and when i click the button class B should inform class A. I should do this by creating an interface between the classes and implementing it. how do i do this ? thanks.
what i have done is this
interface Listener{
void clicked();
}
class A implements Listener{
void clicked(){
// click informed to A
}
}
class B {
Button b = new Button();
Listener l = new A()
// say this method gets called by the button when it is pressed
void buttonIsClicked(){
l.clicked();
}
}
i have done it like this but my guide says that i am creating a new "A" and so its like i am informing to a new guy that the button is clicked. i don't get how do i inform "A" without creating an object of "A".
pls help