0% found this document useful (0 votes)
11 views2 pages

N

This Java applet demonstrates mouse event handling using the MouseListener and MouseMotionListener interfaces. It updates a message and the position of the mouse pointer based on various mouse actions such as clicks, entry, exit, press, release, drag, and move. The current status of the mouse is displayed on the applet's interface as it interacts with the user.

Uploaded by

23r01a66k1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

N

This Java applet demonstrates mouse event handling using the MouseListener and MouseMotionListener interfaces. It updates a message and the position of the mouse pointer based on various mouse actions such as clicks, entry, exit, press, release, drag, and move. The current status of the mouse is displayed on the applet's interface as it interacts with the user.

Uploaded by

23r01a66k1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.awt.

*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="MouseEvents" width=300 height=300>
</applet>*/
public class MouseEvents 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.";
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 = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
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);
}
}

You might also like