1 /* 2 Assignment 1, problem 3: this program creates my version of the Dots problem 3 */ 4 5 package npw; 6 7 import java.awt.Color; 8 import javax.swing.SwingUtilities; 9 import painter.SPainter; 10 import shapes.SCircle; 11 12 public class Dots { 13 14 // The solution to the Dots problem 15 16 private void paintTheImage() { 17 SPainter justin = new SPainter("Blue Dot",800,800); 18 SCircle dot = new SCircle(200); 19 20 //Paints green circles 21 paintGreenCircles(justin,dot); 22 23 //Paints orange circles 24 paintOrangeCircles(justin,dot); 25 26 //Paints blue circles 27 paintBlueCircles(justin,dot); 28 29 //Paints magenta circles 30 paintMagentaCircles(justin,dot); 31 32 } 33 34 private void paintGreenCircles(SPainter justin, SCircle dot) { 35 justin.setColor(Color.GREEN); 36 //Sets radius of circle 37 dot.setRadius(100); 38 //Moves painter forward (towards top of canvas) 39 justin.mfd(294); 40 //Moves painter to the left 41 justin.mlt(294); 42 //Paints first circle 43 justin.paint(dot); 44 //Move painter to center 45 justin.moveToCenter(); 46 47 48 //Moves painter backwards (towards bottom of canvas) 49 justin.mfd(294); 50 //Moves painter to the right 51 justin.mrt(294); 52 //Paints second circle 53 justin.paint(dot); 54 //Moves painter to center 55 justin.moveToCenter(); 56 } 57 58 private void paintOrangeCircles(SPainter justin, SCircle dot) { 59 justin.setColor(Color.ORANGE); 60 //Sets radius of circle 61 dot.setRadius(100); 62 //Moves painter forward (towards top of canvas) 63 justin.mbk(293); 64 //Moves painter to the right 65 justin.mrt(294); 66 //Paints first circle 67 justin.paint(dot); 68 //Move painter to center 69 justin.moveToCenter(); 70 71 72 //Moves painter backwards (towards bottom of canvas) 73 justin.mbk(293); 74 //Moves painter to the right 75 justin.mlt(294); 76 //Paints second circle 77 justin.paint(dot); 78 //Moves painter to center 79 justin.moveToCenter(); 80 81 } 82 83 private void paintBlueCircles(SPainter justin, SCircle dot) { 84 justin.setColor(Color.BLUE); 85 dot.setRadius(150); 86 //Moves painter to the right 87 justin.mrt(175); 88 //Paints first circle 89 justin.paint(dot); 90 //Moves painter back to original position 91 justin.moveToCenter(); 92 93 94 //Moves painter to the left 95 justin.mlt(175); 96 //Paints second circle 97 justin.paint(dot); 98 //Moves painter back to original position 99 justin.moveToCenter(); 100 } 101 102 private void paintMagentaCircles(SPainter justin, SCircle dot) { 103 justin.setColor(Color.MAGENTA); 104 dot.setRadius(20); 105 justin.paint(dot); 106 107 108 //Change radius for larger magenta dots 109 dot.setRadius(50); 110 //Moves painter forward (towards top of canvas) 111 justin.mfd(150); 112 //Paints first circle 113 justin.paint(dot); 114 //Moves painter back to original position (center) 115 justin.moveToCenter(); 116 117 118 //Moves painter backwards (towards bottom of canvas) 119 justin.mbk(150); 120 //Paints second circle 121 justin.paint(dot); 122 //Moves painter back to original position (center) 123 justin.moveToCenter(); 124 125 126 } 127 128 // Required infrastructure \ 129 130 public Dots() { 131 paintTheImage(); 132 } 133 134 public static void main(String[] args) { 135 SwingUtilities.invokeLater(new Runnable() { 136 public void run() { 137 new Dots(); 138 } 139 }); 140 } 141 }