// ProgB7. NEP Java program to demonstrate various mouse handling events using suitable example.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="ProgB7" height="300" width="500">
</applet>
*/
public class ProgB7 extends Applet implements MouseListener
{
Font f1;
String msg="Demonstration of Mouse Events";
public void init()
{
f1 = new Font("Georgia",Font.BOLD,22);
addMouseListener(this);
}
public void mouseClicked(MouseEvent me)
{
msg = "Mouse Clicked";
repaint();
}
public void mousePressed(MouseEvent me)
{
msg = "Mouse Pressed";
repaint();
}
public void mouseReleased(MouseEvent me)
{
msg = "Mouse Released";
repaint();
}
public void mouseEntered(MouseEvent me)
{
msg = "Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
msg = "Mouse Exited";
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.setFont(f1);
g.drawString(msg,20,20);
}
}
No comments :
Post a Comment