1 /* 2 * Program 9 colored dots, Npw. 3 */ 4 5 package npw; 6 7 import painter.SPainter; 8 import shapes.SCircle; 9 import javax.swing.*; 10 import java.awt.*; 11 12 public class Dots { 13 14 // THE SOLUTION TO THE 9 DOT PROBLEM 15 private void paintTheImage() { 16 SPainter corn = new SPainter("Nine Dots",700,550); 17 18 SCircle dot = new SCircle(70); 19 paintpinkCircles(corn,dot); 20 paintmagentaCircles(corn, dot); 21 paintBlueCircle(corn, dot); 22 paintRedCircle(corn, dot); 23 } 24 private void paintpinkCircles(SPainter corn, SCircle dot) { 25 //pink dot on the left 26 corn.mlt(250); 27 corn.setColor(Color.PINK); 28 corn.paint(dot); 29 //invariant 30 corn.moveToCenter(); 31 //same pink dot but on the right 32 corn.mrt(250); 33 corn.setColor(Color.PINK); 34 corn.paint(dot); 35 //invariant 36 corn.moveToCenter(); 37 } 38 private void paintmagentaCircles(SPainter corn, SCircle dot) { 39 //bottom-left magenta dot 40 corn.mbk(90); 41 corn.mlt(130); 42 corn.setColor(Color.magenta); 43 corn.paint(dot); 44 //invariant 45 corn.moveToCenter(); 46 //bottom-right magenta dot 47 corn.mbk(90); 48 corn.mrt(130); 49 corn.setColor(Color.magenta); 50 corn.paint(dot); 51 //invariant 52 corn.moveToCenter(); 53 //lower-mid magenta dot 54 corn.mbk(175); 55 corn.setColor(Color.magenta); 56 corn.paint(dot); 57 //invariant 58 corn.moveToCenter(); 59 } 60 private void paintBlueCircle(SPainter corn, SCircle dot) { 61 //top-left blue dot 62 corn.mfd(90); 63 corn.mlt(130); 64 corn.setColor(Color.blue); 65 corn.paint(dot); 66 //invariant 67 corn.moveToCenter(); 68 //top-right blue dot 69 corn.mfd(90); 70 corn.mrt(130); 71 corn.setColor(Color.blue); 72 corn.paint(dot); 73 //invariant 74 corn.moveToCenter(); 75 //mid-top blue dot 76 corn.mfd(175); 77 corn.setColor(Color.blue); 78 corn.paint(dot); 79 //invariant 80 corn.moveToCenter(); 81 } 82 private void paintRedCircle(SPainter corn, SCircle dot) { 83 corn.setColor(Color.RED); 84 corn.paint(dot); 85 //invariant 86 corn.moveToCenter(); 87 } 88 //REQUIRED INFRASTRUCTURE 89 public Dots() { 90 paintTheImage(); 91 } 92 93 public static void main(String[] args) { 94 SwingUtilities.invokeLater(new Runnable() { 95 public void run() { 96 new Dots(); 97 } 98 }); 99 } 100 } 101 102 103 104 105