Practical-6 Develop an applet that uses the mouse listener, which overrides only two methods which are mousePressed and mouseReleased.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Practical6 extends Applet implements MouseListener {
String msg="";
public void init() {
setSize(400,400);
addMouseListener(this);
}
public void paint(Graphics g)
{
showStatus(msg);
}
public void mousePressed(MouseEvent e)
{
msg="Mouse Pressed";
repaint();
}
public void mouseReleased(MouseEvent e)
{
msg="Mouse Released";
repaint();
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
}
Output:
Comments
Post a Comment