public class A extends Applet implements MouseListener,MouseMotionListener{

     public void init(){

       addMouseListener(this);
       addMouseMotionListener(this);

    }

}

please tell me that what "this" means here!! actually, what argument addMouselistener() function want ? i have seen API, in that it is given "MouseListener e", how it is true here ?? tell me please!! here "this" refering to which object? applet's or interfaces? and how ??

please tell me that what "this" means here!!

this refers to your current class object.(i.e the object by using which you call the method) .Generally , when you want to refer to the object of your class , you can use "this" .

Instead of creating a new object of the class and passing it as parameter , you are using "this" keyword.

addMouseMotionListener(this);

the above is same as

addMouseMotionListener(new A());

but the only difference is the constructor (if present) will execute again in the 2nd case because new object is created.

this refers to your current class object.(i.e the object by using which you call the method) .Generally , when you want to refer to the object of your class , you can use "this" .

Instead of creating a new object of the class and passing it as parameter , you are using "this" keyword.

addMouseMotionListener(this);

the above is same as

addMouseMotionListener(new A());

but the only difference is the constructor (if present) will execute again in the 2nd case because new object is created.

but in the function addMouseListener() we must be give a interface link (MouseListener here,) how we are giving this here ? bcz we are giving A()'s object here in argument.

but in the function addMouseListener() we must be give a interface link (MouseListener here,) how we are giving this here ? bcz we are giving A()'s object here in argument.

you can pass any object of the class that will implement MouseListener interface

public class A extends Applet implements MouseListener,MouseMotionListener{

because you are implementing MouseListener interface in your class , you can pass the
A's object .

The use of implement keyword is that, whenever you use "implement" keyword , you are promising the compiler that you will implement all the methods present in that interface.
Otherwise the compiler will throw you error.

I recommend you to learn the basics of java language so that you'll come to know what is what.
you can find lot of tutorials online..

you can pass any object of the class that will implement MouseListener interface

because you are implementing MouseListener interface in your class , you can pass the
A's object .

hey! ur answers are nyc! can u tell me that when i m calling addlistener() function , what exacltly m doing ? am i adding applet so that these actions can be implemented on applet ??

when you use addlistener , you are registering the applet to listen to any particular event . otherwilse which all the events are ignored..

AS i said , you can find lot of tutorials online.so try to learn and understand by yourself.

If you have a problem understanding the tutorial, please copy the parts that you are having trouble with here and ask questions about the parts you do not understand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.