PR 11 Java
PR 11 Java
PR 11 Java
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
{
public pra()
{
this.addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
int clicks=e.getClickCount();
switch(clicks)
{
case 1:
System.out.println("It is single click");
break;
case 2:
System.out.println("It is double click");
break;
case 3:
System.out.println("It is triple click");
break;
default:
System.out.println("It is multiple clicks");
break;
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e) { }
public static void main (String args[])
{
pra a=new pra();
a.setSize(500,500);
a.setVisible(true);
}
}
package practical;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
{
public pr11()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mousePressed(MouseEvent e)
{
setBackground(Color.red);
}
public void mouseReleased(MouseEvent e)
{
setBackground(Color.green);
}
public void mouseClicked(MouseEvent e)
{
setBackground(Color.green);
}
public void mouseEntered(MouseEvent e)
{
setBackground(Color.darkGray);
}
public void mouseExited(MouseEvent e)
{
setBackground(Color.orange);
}
public void mouseMoved(MouseEvent e)
{
setBackground(Color.cyan);
}
public void mouseDragged(MouseEvent e)
{
setBackground(Color.magenta);
}