Tuesday, 18 March 2014

Mouse handling

This program tells about how to use action Listener methods and its methods along with how to handle the mouse events.whenever you perform such type of functions such as :click,released,drag,move,enter or exit from the window then it reflects your output as by the repaint method:

To Know more about the mouse event functions and its calculations check out the Java Label:

NewClass.java:

import java.awt.event.*;
import java.applet.*;
import java.awt.*;
/*
<applet code="NewClass" width=300 height=100>
</applet>
*/

public class NewClass extends Applet implements MouseListener, MouseMotionListener
{
    String msg=" ";
    int mouseX=0,mouseY=0;
    public void init()
    {
        addMouseListener(this);
        addMouseMotionListener(this);
       
    }
    public void mouseClicked(MouseEvent me)
    {
        mouseX= 0;
        mouseY=10;
        msg="mouse clicked at:"+me.getX()+" ' "+me.getY();
        repaint();
       
    }
    public void mouseEntered(MouseEvent me)
    {
        mouseX=0;
        mouseY=10;
        msg="mouse entered";
        repaint();
       
    }
    public void mouseExited(MouseEvent me)
    { mouseX=0;
        mouseY=10;
        msg="mouse Exited";
        repaint();
       
    }
    public void mousePressed(MouseEvent me)
    {
         mouseX=me.getX();
        mouseY=me.getY();
        msg="Mouse Pressed";
        repaint();
    }
    public void mouseReleased(MouseEvent me)
    {
         mouseX=0;
        mouseY=10;
        msg="mouse Realeased";
        repaint();
    }
    public void mouseDragged(MouseEvent me)
    {
         mouseX=me.getX();
        mouseY=me.getY();
        msg="***";
        showStatus("Dragging mouse at "+ mouseX +" ,"+ mouseY);
        repaint();
    }
    public void mouseMoved(MouseEvent me)
    {
         showStatus("moving mouse at"+ me.getX() + ","+ me.getY());
    }
    public void paint(Graphics g)
    {
        g.drawString(msg,mouseX,mouseY);
    }
}

output:







1 comment:

  1. Review of the Merkur 23c Slot Review【Link Vào Trang Chủ_SODO66.PH
    In a nutshell, the งานออนไลน์ Merkur 23c 메리트 카지노 주소 slot is designed for those who enjoy a high quality 1xbet design, a low cost, and with an excellent design.

    ReplyDelete