import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Mouse" width=500 height=500>
</applet>
*/
public class Mouse extends Applet
implements MouseListener,MouseMotionListener
{
int X=0,Y=20;
String msg="MouseEvents";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
setBackground(Color.black);
setForeground(Color.red);
}
public void mouseEntered(MouseEvent m)
{
setBackground(Color.magenta);
showStatus("Mouse Entered");
repaint();
}
public void mouseExited(MouseEvent m)
{
setBackground(Color.black);
showStatus("Mouse Exited");
repaint();
}
public void mousePressed(MouseEvent m)
{
X=10;
Y=20;
msg="NEC";
setBackground(Color.green);
repaint();
}
public void mouseReleased(MouseEvent m)
{
X=10;
Y=20;
msg="Engineering";
setBackground(Color.blue);
repaint();
}
public void mouseMoved(MouseEvent m)
{
X=m.getX();
Y=m.getY();
msg="College";
setBackground(Color.white);
showStatus("Mouse Moved");
repaint();
}
public void mouseDragged(MouseEvent m)
{
msg="CSE";
setBackground(Color.yellow);
showStatus("Mouse Moved"+m.getX()+" "+m.getY());
repaint();
}
public void mouseClicked(MouseEvent m)
{
msg="Students";
setBackground(Color.pink);
showStatus("Mouse Clicked");
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,X,Y);
}
}
Output:
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.
21 thoughts on “Java applet program for handling mouse events”
Haha well done now try creating an AI that beats mine wihtuot using recursive search! I created the AI to enter into a competition where I had the restriction of being unable to track game/move history or use recursive search/evaluation methods. My AI placed first in this branch of the competition. The organisers of the competition believed my AI could have beaten the recursive entries too if I had of developed it into a recursive player something I’d like to do but I don’t have the time at the moment!
thank u sooooooooooooooo much sir
thank so much its useful to all
once again thank you so much
good
it wont show up in my jcreator
good program
thanks
but i am getting error
Error: Main method not found in class Mouse, please define the main method as:
public static void main(String[] args)
this error occurs what does it mean
Haha well done now try creating an AI that beats mine wihtuot using recursive search! I created the AI to enter into a competition where I had the restriction of being unable to track game/move history or use recursive search/evaluation methods. My AI placed first in this branch of the competition. The organisers of the competition believed my AI could have beaten the recursive entries too if I had of developed it into a recursive player something I’d like to do but I don’t have the time at the moment!
thank u sooooooooooooooo much sir
thank so much its useful to all
once again thank you so much
good
it wont show up in my jcreator
good program
thanks
but i am getting error
Error: Main method not found in class Mouse, please define the main method as:
public static void main(String[] args)
this error occurs what does it mean
bro applet doesn’t support main method hehehehe ots combination of HTML n JAVA
This program is fully copied from Complete Reference,so there is no need to appreciate him……..