1 package npw; 2 import painter.SPainter; 3 import shapes.SCircle; 4 import shapes.SRectangle; 5 import shapes.SSquare; 6 7 import javax.swing.*; 8 import java.awt.*; 9 import java.util.Random; 10 11 public class Invention2 { 12 private void paintTheImage() 13 { 14 SPainter inventor2= new SPainter("Inventor",800,800); 15 SRectangle rectangle=new SRectangle(100,100); 16 int x=1; 17 Random rand=new Random(); 18 while(x<6) 19 { 20 if(inventor2.color== Color.BLUE) 21 { 22 inventor2.setColor(Color.RED); 23 inventor2.paint(rectangle); 24 25 inventor2.mfd(rand.nextInt(100)); 26 } 27 else if(inventor2.color==Color.RED) 28 { 29 inventor2.setColor(Color.BLUE); 30 inventor2.paint(rectangle); 31 inventor2.mfd(rand.nextInt(100)); 32 } 33 else 34 { 35 inventor2.setColor(Color.RED); 36 inventor2.paint(rectangle); 37 inventor2.mfd(rand.nextInt(100)); 38 } 39 x++; 40 } 41 } 42 public Invention2() 43 { 44 paintTheImage(); 45 } 46 public static void main(String[] args) 47 { 48 SwingUtilities.invokeLater(new Runnable() { 49 public void run() { 50 new Invention2(); 51 } 52 }); 53 } 54 } 55