30-08-2011, 12:32 PM
Code:
/* Mouse Events */
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class LMouseEvents extends Applet
implements MouseListener,MouseMotionListener
{
String msg=" ";
int mousex = 0,mousey = 0;
public void init()
{
setBackground(Color.cyan);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
mousex = me.getX();
mousey = me.getY();
msg = "Mouse Clicked";
setBackground(Color.green);
repaint();
}
public void mouseEntered(MouseEvent me)
{
mousex = me.getX();
mousey = me.getY();
msg="MouseEntered";
setBackground(Color.red);
repaint();
}
public void mouseExited(MouseEvent me)
{
mousex = me.getX();
mousey = me.getY();
msg="Mouse Exited";
setBackground(Color.black);
repaint();
}
public void mousePressed(MouseEvent me)
{
mousex=me.getX();
mousey=me.getY();
msg="Down";
setBackground(Color.pink);
repaint();
}
public void mouseReleased(MouseEvent me)
{
mousex = me.getX();
mousey = me.getY();
msg = "up";
setBackground(Color.magenta);
repaint();
}
public void mouseDragged(MouseEvent me)
{
mousex = me.getX();
mousey = me.getY();
msg = "Ravi Krishna.M";
setBackground(Color.lightGray);
repaint();
}
public void mouseMoved(MouseEvent me)
{
setBackground(Color.orange);
showStatus("Moving mouse at"+me.getX()+","+me.getY());
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.drawString(msg,mousex,mousey);
}
}