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