MouseListener interface and MouseEvent class in java
//MouseListener interface and MouseEvent class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
<applet code = "MouseListener_and_MouseEvent"
width = 200 height = 200></applet>
*/
public class MouseListener_and_MouseEvent extends JApplet
implements MouseListener
{
Container con;
public void init()
{
con = getContentPane();
con.setLayout(new FlowLayout());
addMouseListener(this);
}
public void mouseEntered(MouseEvent me)
{
con.setBackground(Color.red);
}
public void mouseExited(MouseEvent me)
{
con.setBackground(Color.green);
}
public void mousePressed(MouseEvent me)
{
con.setBackground(Color.blue);
}
public void mouseReleased(MouseEvent me)
{
con.setBackground(Color.yellow);
}
public void mouseClicked(MouseEvent me)
{
con.setBackground(Color.black);
}
}
OUTPUT:
Comments
Post a Comment