1 /* 2 * Program to paint a red cross in the context of the Nonrepresentational Painting World (NPW) 3 * Paint a red cross in a 600 x 600 canvas whose legs are 500 x 100 4 * Featured Constraint: Create and use only one rectangle 5 */ 6 7 package npw; 8 9 import java.awt.Color; 10 import javax.swing.SwingUtilities; 11 import painter.SPainter; 12 import shapes.SRectangle; 13 14 public class RedCross { 15 //THE SOLUTION TO THE RED CROSS PROBLEM 16 private void paintTheImage() { 17 //Create the canvas 600 x 600 18 SPainter canvas = new SPainter("Red Cross", 600, 600); 19 20 //Create the vertical rectangle 500 x 100 and color red 21 SRectangle rectangle = new SRectangle(500, 100); 22 canvas.setColor(Color.RED); 23 canvas.paint(rectangle); 24 25 canvas.tl(); 26 //Create the horizontal rectangle 100 x 500 and color red using the existing rectangle object 27 //rectangle.setHeight(100); 28 //rectangle.setWidth(500); 29 canvas.setColor(Color.RED); 30 canvas.paint(rectangle); 31 } 32 33 //REQUIRED INFRASTRUCTURE 34 public RedCross() { 35 paintTheImage(); 36 } 37 38 public static void main(String[] args) { 39 SwingUtilities.invokeLater(new Runnable() { 40 public void run() { 41 new RedCross(); 42 } 43 }); 44 } 45 } 46