JAVA Program to Implement Mouse Operations using Mouse Event Handling

JAVA Program to Implement Mouse Operations using Mouse Event Handling:

/*

<APPLET
 CODE = MouseEventHandle.class
 WIDTH=600
 HEIGHT=400>
 </APPLET>
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class MouseEventHandle extends Applet
                         implements MouseListener

{

   String msg="";
   int Xcordinate=0,Ycordinate=0;


   public void init()
   {
    addMouseListener(this);
   }


    public void mouseClicked(MouseEvent me)
    {
      Xcordinate=0;
      Ycordinate=20;
      msg="Mouse clicked Event";
      repaint();
    }


    public void mouseEntered(MouseEvent me)
    {
      Xcordinate=0;
      Ycordinate=20;
      msg="Mouse Entered Event";
      repaint();
    }


     public void mouseExited(MouseEvent me)
    {
      Xcordinate=0;
      Ycordinate=20;
      msg="Mouse Exited Event";
      repaint();
    }

    public void mousePressed(MouseEvent me)
        {
          Xcordinate=0;
          Ycordinate=20;
          msg="Mouse Pressed Event";
          repaint();
    }


    public void mouseReleased(MouseEvent me)
        {
          Xcordinate=0;
          Ycordinate=20;
          msg="Mouse Released Event";
          repaint();
    }


    public void paint(Graphics g)
     {
        g.drawString(msg, Xcordinate=0,Ycordinate=20);
     }

}

OUTPUT:

JAVA Program to Implement Mouse Operations using Mouse Event Handling

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.