Write a java applet Program to perform Mouse Event
import java.applet.Applet;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Event;
public class MouseEvents extends Applet implements MouseListener,MouseMotionListener
{
String msg = " ";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
g.drawString(msg,20,20);
}
public void mousePressed(MouseEvent me)
{
msg="MousePressed";
repaint();
}
public void mouseEntered(MouseEvent me)
{
msg="MouseEntered";
repaint();
}
public void mouseClicked(MouseEvent me)
{
msg="MouseClicked";
repaint();
}
public void mouseExited(MouseEvent me)
{
msg="MouseExited";
repaint();
}
public void mouseReleased(MouseEvent me)
{
msg="MouseReleased";
repaint();
}
public void mouseMoved(MouseEvent me)
{
msg="MouseMoved";
repaint();
}
public void mouseDropped(MouseEvent me)
{
msg="MouseDropped";
repaint();
}
public void mouseDragged(MouseEvent me)
{
msg="MouseDragged";
repaint();
}
}
********************************************************************
HTML
<html>
<applet code="MouseEvents.class" width="800" height="500">
</applet>
</html>
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Event;
public class MouseEvents extends Applet implements MouseListener,MouseMotionListener
{
String msg = " ";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
g.drawString(msg,20,20);
}
public void mousePressed(MouseEvent me)
{
msg="MousePressed";
repaint();
}
public void mouseEntered(MouseEvent me)
{
msg="MouseEntered";
repaint();
}
public void mouseClicked(MouseEvent me)
{
msg="MouseClicked";
repaint();
}
public void mouseExited(MouseEvent me)
{
msg="MouseExited";
repaint();
}
public void mouseReleased(MouseEvent me)
{
msg="MouseReleased";
repaint();
}
public void mouseMoved(MouseEvent me)
{
msg="MouseMoved";
repaint();
}
public void mouseDropped(MouseEvent me)
{
msg="MouseDropped";
repaint();
}
public void mouseDragged(MouseEvent me)
{
msg="MouseDragged";
repaint();
}
}
********************************************************************
HTML
<html>
<applet code="MouseEvents.class" width="800" height="500">
</applet>
</html>
Leave a Comment