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