source code name: MouseDemo2.java

     import java.awt.*;
     import java.awt.event.*;
 class MouseDemo2 extends Frame implements MouseListener
{
String str="wel come";
int x,y;
 public MouseDemo2()
{  
addMouseListener(this);
}
 
public void mousePressed(MouseEvent me)
{
System.out.println("mouse is Pressed");
x=me.getX();
y=me.getY();
str="[ x= "+x+" , y="+ y+" ]";
repaint();
}
public void mouseReleased(MouseEvent me){

}
public void mouseClicked(MouseEvent me){

}
public void mouseEntered(MouseEvent me){

}
public void mouseExited(MouseEvent me){
}
public void paint(Graphics g)
{
g.drawString(str,x,y);
}
 public static void main(String[] args)
{  
MouseDemo2 f=new MouseDemo2();
f.setTitle("Mouse Event program");
f.setSize(400,500);  
 f.setVisible(true);  
    }
}  

output: