mouseevent in java


-program based on mouseevent in  java-----
-

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


/*
<applet code="mouse" width=600 height=500>
</applet>
*/
public class mouse extends Applet
implements MouseListener,MouseMotionListener
{
int X=10,Y=50;
String msg="MouseEvents";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
setBackground(Color.yellow);
setForeground(Color.red);
}
public void mouseEntered(MouseEvent m)
{
setBackground(Color.blue);
showStatus("Mouse Entered");
repaint();
}
public void mouseExited(MouseEvent m)
{
setBackground(Color.black);
showStatus("Mouse Exited");
repaint();
}
public void mousePressed(MouseEvent m)
{
X=20;
Y=40;
msg="GTBIT";
setBackground(Color.pink);
repaint();
}
public void mouseReleased(MouseEvent m)
{
X=20;
Y=40;
msg="Engineering";
setBackground(Color.magenta);
repaint();
}
public void mouseMoved(MouseEvent m)
{
X=m.getX();
Y=m.getY();
msg="College";
setBackground(Color.white);
showStatus("Mouse Moved");
repaint();
}
public void mouseDragged(MouseEvent m)
{
msg="IT-INFORMATION TECHNOLOGY";
setBackground(Color.yellow);
showStatus("Mouse Moved"+m.getX()+" "+m.getY());
repaint();
}
public void mouseClicked(MouseEvent m)
{
msg="Students";
setBackground(Color.pink);
showStatus("Mouse Clicked");
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,X,Y);
}
}

Comments