PR 11 Java

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

package practical;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class pra extends JFrame implements MouseListener

{
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 class pr11 extends Frame implements MouseListener,


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);
}

public static void main(String args[])


{
pr11 a1= new pr11();
a1.setSize(300,300);
a1.setVisible(true);
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Ex16 extends Applet implements MouseMotionListener
{
public void init()
{
addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent me)
{
showStatus("Mouse is moved to :"+me.getX()+","+me.getY());
}
public void mouseDragged(MouseEvent me)
{
showStatus("Mouse dragged to :"+me.getPoint());
}
}
/*
<applet code=Ex16 height=300 width=300>
</applet>
*/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy