Java's Drawing art pattern

Source: Internet
Author: User

Package com.caiduping; Import Java.awt.color;import java.awt.graphics;import Java.awt.graphics2d;import Java.awt.geom.ellipse2d;import Java.util.random;import Javax.swing.jframe;import Javax.swing.JPanel;         public class Artdesignframe extends JFrame {artdesignpanel Artdesignpanel = new Artdesignpanel ();//Create an instance of the Panel class public static void Main (String args[]) {//Main method Artdesignframe frame = new Artdesignframe ();//Create an instance of the form class FRA Me.setvisible (TRUE); Show form} public Artdesignframe () {super ();//Call the constructor method of the superclass Settitle ("Draw Art");//form title Setb Ounds (100, 100, 338, 230); The display position and size of the form setdefaultcloseoperation (Jframe.exit_on_close); Form off mode Add (Artdesignpanel);     Add an instance of the Panel class to the form container} class Artdesignpanel extends JPanel {//create Inner panel class public void Paint (Graphics g) { Rewrite the paint () method graphics2d g2 = (graphics2d) g; Get Graphics2D object Ellipse2d.float ellipse = new Ellipse2d.float (-80, 5, 160, 10);/Create ellipse object random random = new random ();//create random Number Object G2.translate (160, 90);//translation Axis int r = r Andom.nextint (256);//The R value of the randomly generated color int G = Random.nextint (256);//The G value of the randomly generated color int B = Random.nextint (256); /randomly produces a color B-value color color = new color (r,g,b);//Creates a Color object G2.setcolor (color);//Specifies a color G2.draw (Elli            PSE);//Draw ellipse int i=0;                while (i<100) {r = Random.nextint (256);//R value of randomly generated color G = Random.nextint (256);//randomly generated G value of color b = Random.nextint (256);//randomly produce a color of B-value color = new color (r,g,b);//Create a new colour object g2.setc            Olor (color);//Specify Color g2.rotate (10);//rotate Canvas g2.draw (ellipse);//Draw Ellipse i++; }        }    }}

Run

 

Java's Drawing art pattern

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.