import java.awt.*;
import java.awt.event.*;
import java.applet.*;
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=" mouse pressed";
repaint();
}
public void mouseClicked(MouseEvent me)
{
msg=" mouse clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
msg=" mouse entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
msg=" mouse exited";
repaint();
}
public void mouseReleased(MouseEvent me)
{
msg=" mouse released";
repaint();
}
public void mouseMoved(MouseEvent me)
{
msg=" mouse moved";
repaint();
}
public void mouseDropped(MouseEvent me)
{
msg=" mouse dropped";
repaint();
}
public void mouseDragged(MouseEvent me)
{
msg=" mouse dragged";
repaint();
}
}
HTML Code
<html>
<title>Keyboard Events</title>
<Body><Applet code="MouseEvents.class" height=100 width=700></applet>
</body>
</html>
Output
import java.awt.event.*;
import java.applet.*;
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=" mouse pressed";
repaint();
}
public void mouseClicked(MouseEvent me)
{
msg=" mouse clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
msg=" mouse entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
msg=" mouse exited";
repaint();
}
public void mouseReleased(MouseEvent me)
{
msg=" mouse released";
repaint();
}
public void mouseMoved(MouseEvent me)
{
msg=" mouse moved";
repaint();
}
public void mouseDropped(MouseEvent me)
{
msg=" mouse dropped";
repaint();
}
public void mouseDragged(MouseEvent me)
{
msg=" mouse dragged";
repaint();
}
}
HTML Code
<html>
<title>Keyboard Events</title>
<Body><Applet code="MouseEvents.class" height=100 width=700></applet>
</body>
</html>
Output
No comments:
Post a Comment