BCA

AJAVA LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

 
 

Question  5:Write a Java program that handles all mouse events and shows the event name at the center of the
window when a mouse event is fired and trace the mouse pointer path only for dragging.

/ *<applet code="mouseevent" height=100 width=300></ applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class mouseevent extends Applet implements MouseListener,
MouseMotionListener
{
final Font fnt=new Font("Verdana",Font.PLAIN,20);
String msg=" ";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
g.setFont(fnt);
g.drawString(msg,20,3 0);
}
public void mouseEntered(MouseEvent me)
{msg="mouse entered";
repaint();
}
public void mousePressed(MouseEvent me)
{
msg="mouse pressed";
repaint();
}
public void mouseClicked(MouseEvent me)
{
msg="mouse clicked";
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();
}
}