AJP Practical11

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

Practical No 11:

***Write a program to change the background color of Applet when user performs event using
Mouse.

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

public class MouseColor extends Applet implements MouseMotionListener


{
public void init()
{
addMouseMotionListener(this);
}

public void mouseDragged(MouseEvent me)


{
setBackground(Color.red);
repaint();
}

public void mouseMoved(MouseEvent me)


{
setBackground(Color.green);
repaint();
}

}
/*
<applet code="MouseColor" width=300 height=300>
</applet>

*/Output:-
** Write a program to count the number of clicks performed by the user in a applet?

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

public class MouseCount extends Applet implements MouseListener


{
int count = 0;
public void init()
{
addMouseListener(this);
}

public void mouseClicked(MouseEvent me)


{
count++;
showStatus("Number of time Clicked:"+count);
repaint();
}

public void mouseEntered(MouseEvent me)


{
}
public void mouseExited(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
}
/*
<applet code="MouseCount" width=300 height=300>
</applet>
*/

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