A very basic applet that can be embedded in other applications as a method
Import Java.awt.Graphics;
Import java.awt.Event;
Import Java.awt.Color;
public class Mouse extends Java.applet.Applet
{
int num=0;//counter initialization
int px,py;
The public boolean MouseDown (event evt,int x,int y)//mouse presses events
{
Px=x;
py=y;//the coordinates of the mouse when pressed
num++;//counter plus 1
repaint ()//Redraw window
Return true;//returns True to indicate that the event has been processed
}
public void Update ( Graphics g)
{
G.setcolor (Getbackground ());//Remove a fast area with background color
G.fillrect (10,300,200,60);
Paint (g);//Call Paint Method
}
public void Paint (Graphics g)
{
G.setcolor (color.green);
g.DrawString ("The current mouse coordinates are (" +px+ "," +py+ ")", 10,300),//outputs the coordinates of the current mouse
g.DrawString ("This is No." +num+ "point", 10,340)//output clicks
G.setcolor (color.red);//Draw a red fork in the mouse click Position
G.drawline (px-5,py-5,px+5,py+5);
G.drawline (px+5,py-5,px-5,py+5);
}
<title>111</title>
<body>
<applet code= "Mouse.class" width=300 height=350></applet>
</body>