Practical 11

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

Practical No – 11

Batch – T1 l.setText("Mouse Entered");

Program - 1 }

import java.applet.Applet; import public void mouseExited(MouseEvent e)


java.awt.*; import {
java.awt.event.*; l.setText("Mouse exited");
/* <applet code ="MouseDemo.class" }
width=300 height=300> </applet> */
public void mouseClicked(MouseEvent e)
public class MouseDemo extends Applet
implements MouseListener {

{ Label l; public l.setText("mouse clicked(# of


clicks:"+e.getClickCount());
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)
{
Program - 2
import java.awt.*; import java.applet.*; addMouseListene
import java.awt.event.*;
r(this);
/*<applet code="MouseEventColor.class"
height=400 width=400> </applet>*/ }
public class MouseEventColor extends public void mousePressed(MouseEvent e)
Applet implements MouseListener
{
{ Label l; public
setBackground(Color.green);
void init() { showStatus("mouse pressed"); repaint();
setLayout(null); }
l=new public void mouseReleased(MouseEvent e)
Label("Hello {
Mouse"); setBackground(Color.blue);
showStatus("mouse released"); repaint();
} setBackground(Color.black);
showStatus("mouse exited"); repaint();
public void mouseEntered(MouseEvent e)
} { public void
mouseClicked(MouseEvent e)
setBackground(Color.red);
showStatus("mouse entered"); repaint(); {
} setBackground(Color.yellow);
showStatus("mouse clicked"); repaint();
public void mouseExited(MouseEvent e)
}
{
}
Program - 3 {

import java.awt.*; import java.applet.*; TextField l; public void init()


import java.awt.event.*;
{
/*<applet code="NumClicks.class"
l=new TextField("Hello Mouse",35); add(l);
height=300 width=300>
addMouseListener(this);
</applet>*/
}
public class NumClicks extends Applet
implements MouseListener public void mousePressed(MouseEvent e)
{ Program - 4
} import java.awt.*; import java.applet.*; import
java.awt.event.*;

/*<applet code="MouseMethods.class" width=300


public void mouseReleased(MouseEvent e)
height=300> </applet>*/
{
public class MouseMethods extends Applet
} implements MouseMotionListener

{
public void mouseEntered(MouseEvent e)
TextField t=new TextField(20); public void init()
{
{
}
add(t); addMouseMotionListener(this);
public void mouseExited(MouseEvent e)
}
{ pu
bli
} c
voi
public void mouseClicked(MouseEvent e) d
mo
{ use
Mo
l.setText("mouse clicked (Total number of ved
(M
clicks ):" +e.getClickCount()); repaint();
ous
} eE
ven
} t
me
)

{
setBackground(Color.blue); setBackground(Color.red);
t.setText("mouseMoved"); } t.setText("mouseDragged");

public void mouseDragged(MouseEvent me) }

{ }

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