Mouse event example1
The source code of this example is as follows:
Import java. applet .*;
Import java. awt .*;
// As mentioned in the previous example, I will not continue. Pai_^
Public class Aa1 extends Applet
{
Int cx = 50;
Int cy = 50;
// Define the initial position of the mouse, that is, the string that appears when you have not pressed the mouse
.
Public boolean mouseDown (Event e, int x, int y)
// Define the mouse-down function. This is a Boolean function, that is, there are only real and false functions.
Status function.
// Parameter e is the mouse-pressed parameter. When the mouse is pressed, the e value is true, and x and y are the mouse's
Location parameter.
{
Cx = x;
Cy = y;
// Re-define the position parameter of the string so that the position of the string is the position where the mouse is pressed.
Repaint ();
// Re-draw the screen to update the string position.
Return true;
// Return the function. This function is true.
}
Public void paint (Graphics g)
// The paint function and screen rendering function. The browser starts to know how to draw the screen,
Draw something.
// Draw a string at the cx and cy positions to display it.
{
G. drawString ("where to press the mouse, I will show it! ", Cx, cy );
}
}