1 /* 2 *Program to paint a Kanizsa Square 3 * 4 */ 5 6 package npw; 7 8 import java.awt.Color; 9 import javax.swing.SwingUtilities; 10 import painter.SPainter; 11 import shapes.SCircle; 12 import shapes.SSquare; 13 14 public class KanizsaSquare { 15 16 private void paintTheImage() { 17 SPainter painter = new SPainter("Kanizsa Sqaure",400,400); 18 19 SCircle dot = new SCircle(75); 20 paintBlueCircle(painter, dot); 21 paintRedCircle(painter, dot); 22 paintGreenCircles(painter, dot); 23 24 SSquare square = new SSquare(200); 25 paintWhiteSquare(painter, square); 26 27 } 28 29 private void paintWhiteSquare(SPainter painter, SSquare square) { 30 painter.setColor(Color.WHITE); 31 painter.paint(square); 32 } 33 34 private void paintGreenCircles(SPainter painter, SCircle dot) { 35 painter.setColor(Color.GREEN); 36 painter.mfd(100); 37 painter.mrt(100); 38 painter.paint(dot); 39 painter.mlt(100); 40 painter.mbk(200); 41 painter.mlt(100); 42 painter.paint(dot); 43 painter.mrt(100); 44 painter.mfd(100); 45 } 46 47 private void paintRedCircle(SPainter painter, SCircle dot) { 48 painter.setColor(Color.RED); 49 painter.mbk(100); 50 painter.mrt(100); 51 painter.paint(dot); 52 painter.mlt(100); 53 painter.mfd(100); 54 } 55 56 private void paintBlueCircle(SPainter painter, SCircle dot) { 57 painter.setColor(Color.BLUE); 58 painter.mfd(100); 59 painter.mlt(100); 60 painter.paint(dot); 61 painter.mrt(100); 62 painter.mbk(100); 63 } 64 65 public KanizsaSquare() { 66 paintTheImage(); 67 } 68 69 public static void main(String[] args) { 70 SwingUtilities.invokeLater(new Runnable() { 71 public void run() { 72 new KanizsaSquare(); 73 } 74 }); 75 } 76 } 77