[JAVA100 example]026, basic graphic drawing

Source: Internet
Author: User

Import java.awt.*
Import javax.swing.*
/**
* <p>title: Drawing of basic graphics </p>
* <p> Description: This example demonstrates the drawing of basic graphics such as quadrilateral, rounded rectangles, ellipses, and so on. </p>
* <p>copyright:copyright (c) 2003</p>
* <P>FILENAME:SAMPLE.JAVA</P>
* @ Version 1.0
*/
public class Sample extends JFrame {
/**
*<br> Method Description: Main method
*<br> input parameters:
*<   br> return type:
/
public static void Main (string[] args) {
Sample SL = new sample ();
Sl.update ();
}
/**
*<br> method Description: Builder, displaying form
*<br> input parameters:
*<br> return type:
/
Sample () {
Super ( "Sample");
Setdefaultcloseoperation (jframe.dispose_on_close);
SetSize (310,160);
Show ();   
}
/**
*<br> Method Description: Update screen
*<br> input parameters:
*<br> return type:
*/
public void Update () {
Repaint ();
}
/**
*<br> Method Description: Drawing screen
*<br> input parameters:
*<br> return type:
/
public void paint (Graphics G{
int [] x={10,30,80,50,10};
int [] y={90,140,120,100,90};
G.setcolor (Color.cyan);   
//Draw a vertical bar
for (int i=0; i<=300; i+=10) {
G.drawline (i,0,i,150);
  
//Draw horizontal bars
for (int i=0; i<=150; i+=10) {
G.drawline (0,i,300,i);
}
G.setcolor (Color.Black);   
//Angled Rectangle, starting point (10,30), width 80, height
G.drawrect (10,30,80,50);
   Rounded Rectangle, starting point (110,30), width 80, height 50, angle (a=20,b=10)
G.drawroundrect (110,30,80,50,20,10);
   Multi-corner
G.drawpolygon (x,y,5);
   Ellipse, center of the Circle (110,90), a=80,b=50
G.drawoval (110,90,80,50);
   An arc, the center of the Circle (219,30), the a=80,b=50 angle between 0-90
G.drawarc (210,30,80,50,0,90);
 Slices, center (219,90), a=80,b=50 angle between 0-90
G.fillarc (210,90,80,50,0,90);
}
}

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.