AJP 11
AJP 11
AJP 11
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
Pratical No:-11
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="MouseEventColor.class" height=400 width=400>
</applet>*/
public class MouseEventColor extends Applet implements MouseListener
{
Label l;
public void init()
{
setLayout(null);
l=new Label("Hello Mouse");
addMouseListener(this);
}
public void mousePressed(MouseEvent e)
{
setBackground(Color.green);
showStatus("mouse pressed");
repaint();
}
public void mouseReleased(MouseEvent e)
{
setBackground(Color.blue);
showStatus("mouse released");
repaint();
}
public void mouseEntered(MouseEvent e)
Pratical No:-11
{
setBackground(Color.red);
showStatus("mouse entered");
repaint();}
public void mouseExited(MouseEvent e)
{
setBackground(Color.black);
showStatus("mouse exited");
repaint();
}
public void mouseClicked(MouseEvent e)
{
setBackground(Color.yellow);
showStatus("mouse clicked");
repaint();
}
}
Output
Pratical No:-11
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="NumClicks.class" height=300 width=300>
</applet>*/
public class NumClicks extends Applet implements MouseListener
{
TextField l;
public void init()
{
l=new TextField("Hello Mouse",35);
add(l);
addMouseListener(this);
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
Pratical No:-11
{
l.setText("mouse clicked (Total number of clicks ):"
+e.getClickCount());
repaint();
}
}
Output
setBackground(Color.blue); t.setText("mouseMoved");
}
public void mouseDragged(MouseEvent me)
{
setBackground(Color.red); t.setText("mouseDragged");
}
}
Output