Java applet program for handling mouse events

Sunday, October 4th, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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:

Java mouse handling events

Java mouse handling events

Author Name :
Ranjith

Total : 15 Comments


15 Responses to “Java applet program for handling mouse events”

  1. Suresh says:

    Very Good and Useful Programs Written by You …..
    Thanks a lot For these type of Programs…
    Suresh

  2. Miss. Nayan says:

    thanks,

  3. Ela says:

    Thank you!
    a short & good example :)

  4. ashwini says:

    please give explanation for this programme

  5. surya says:

    how i will get an applet window bro

  6. simply says:

    Its such as you scan my mind! You appear to understand therefore much regarding this, such as you wrote the book in it or something. I think that you could do with some pics to drive the message home a little bit, however other than that, this can be nice blog. A great read.

  7. praveen says:

    nice………..

  8. Karthi says:

    Thank you sir

  9. bampi says:

    didnt understand…..:0

  10. vijin says:

    in which format the file will save and execute in cmd

  11. vijin says:

    in which format the file will save and execute in cmd
    and which class name we will give as file name

  12. Auth says:

    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!

  13. Divya says:

    thank u sooooooooooooooo much sir

  14. aaqila says:

    thank so much its useful to all
    once again thank you so much

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: