PracticalNo11
PracticalNo11
PracticalNo11
: 11
Practical Name: Write a program to demonstrate various mouse events using MouseListener and
MouseMotion listener interface.
Roll No.: 47
Program:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/* <APPLET CODE ="MouseDemo" WIDTH=300 HEIGHT=200> </APPLET> */
public class MouseDemo extends Applet implements MouseListener
{
Label l;
public void init()
{
setLayout(null);
l=new Label("Hello Mouse");
l.setBounds(50,150,200,100);
add(l);
}
public void mousePressed(MouseEvent e)
{
l.setText("Mouse Pressed no. of clicks:" + e.getClickCount() + "atposition" +
e.getX() + ","+ e.getY());
}
public void mouseReleased(MouseEvent e)
{
l.setText("Mouse Released; # of clicks:"+e.getClickCount());
}
public void mouseEntered(MouseEvent e)
{
l.setText("Mouse Entered");
}
public void mouseExited(MouseEvent e)
{
l.setText("Mouse exited");
}
public void mouseClicked(MouseEvent e)
{
l.setText("mouse clicked(# of clicks:"+e.getClickCount());
}
}
Output: