My first JApplet-drawing smiling faces, japplet-drawing smiling faces

Source: Internet
Author: User

My first JApplet-drawing smiling faces, japplet-drawing smiling faces

BeginnerJavaThere are many things that I don't quite understand, but I don't know much about it when I was a beginner in C language. I first read the program in the book, and then I naturally understood it when I used more!

Next, let's briefly introduce the first small Java app I learned by myself-drawing smiling faces. below is the source code and parsing

Source code:

Import java. awt. Graphics;
Import javax. swing. JApplet;
Public class face extends JApplet
{

 

Public void paint (Graphics canvas)
{
Canvas. drawOval (200,200, 50 );
Canvas. fillOval (155,100, 10, 20 );
Canvas. fillOval (230,100, 10, 20 );
Canvas. drawArc (150,160,100, 50,180,180 );
}
}

 

Simple parsing: the first two lines of the program are descriptive statements, similar to the file inclusion statement in C language. The "public class face" statement is the class statement we created. The "extends JApplet" statement indicates that we are defining a small application rather than other classes. This is very important. Without these two words, compile

If the main method is not available, then the applet cannot run. The content is the specific method of drawing!

 

 

Run:

 

 

 

 

Conclusion: The journey of a thousand miles begins with a step!

 

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.