/* * An invention of rectangles that will output different results each time it is ran */ package npw; import painter.SPainter; import shapes.SRectangle; import javax.swing.*; import java.awt.*; public class Invention2 { private void paintTheImage() { SPainter first = new SPainter("Invention2", 700, 700); SRectangle rectangle = new SRectangle(140,170); first.moveToCenter(); first.setColor(Color.RED); first.move(); first.paint(rectangle); int i = 0; while ( i < rectangle.height() ){ if (i == 5) { first.faceNorth(); first.paint(rectangle); first.faceNorth(); first.move(); first.setColor(Color.ORANGE); first.paint(rectangle); first.faceNorth(); first.move(); first.setColor(Color.BLACK); first.paint(rectangle); } if (i == 10) { first.faceNorth(); first.move(); first.setColor(Color.YELLOW); first.paint(rectangle); first.faceNorth(); first.move(); first.setColor(Color.GREEN); first.paint(rectangle); first.faceNorth(); first.move(); first.setColor(Color.BLUE); first.paint(rectangle); } i=i+1; } } public Invention2() { paintTheImage(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Invention2(); } }); } }