AJP 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Pratical No:-11

Name:-Nihal Ayub Tamboli


Roll No:-2218 Batch:-T1

import java.applet.Applet; import java.awt.*;


import java.awt.event.*;
/* <applet code ="MouseDemo.class" width=300 height=300>
</applet> */
public class MouseDemo extends Applet implements MouseListener
{
Label l;
public void init()
{
setLayout(null);
l=new Label("Hello Mouse"); l.setBounds(30,100,150,90); add(l);
l.addMouseListener(this);
}
public void mousePressed(MouseEvent e)
{
l.setBounds(30,100,150,90); l.setText("Mouse Pressed no. of clicks:" +
e.getClickCount() + "atposition" +
e.getX()+ ","+ e.getY());
}
public void mouseReleased(MouseEvent e)
{
l.setText("Mouse Released; # of clicks:"+e.getClickCount());
}
public void mouseEntered(MouseEvent e)
{
Pratical No:-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

import java.awt.*; import java.applet.*; import java.awt.event.*;


/*<applet code="MouseMethods.class" width=300 height=300>
</applet>*/
public class MouseMethods extends Applet implements MouseMotionListener
{
TextField t=new TextField(20); public void init()
{
add(t); addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent me)
{
Pratical No:-11

setBackground(Color.blue); t.setText("mouseMoved");
}
public void mouseDragged(MouseEvent me)
{
setBackground(Color.red); t.setText("mouseDragged");
}
}
Output

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