The fourth day of getting started with Java Applet

Source: Internet
Author: User

 

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 );
  
}
  
}
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.