import java.awt.*; public class DrawRings extends Canvas { Hanoi aHanoi; public DrawRings(Hanoi aHanoi) { this.aHanoi = aHanoi; // addMouseListener(new DoHanoi(aHanoi, this)); // setSize(600, 160); resize(600, 160); setBackground(Color.blue); } public void paint(Graphics g) { g.setFont(new Font("Helvetica", Font.BOLD, 16)); for (int indexOfTower = 0; indexOfTower < 3; indexOfTower++) { g.setColor(Color.white); g.fillRect(95 + 200 * indexOfTower, 0, 10, 160); for (int indexOfRing = 0; indexOfRing < aHanoi.sizeOfTower(indexOfTower); indexOfRing++) { int valueOfRing = aHanoi.valueOfRing(indexOfTower, indexOfRing); switch (valueOfRing % 3) { case 0: g.setColor(Color.green); break; case 1: g.setColor(Color.red); break; case 2: g.setColor(Color.yellow); break; } g.fillRect(indexOfTower * 200 + 100 - 12 * valueOfRing, 140 - indexOfRing * 20, 24 * valueOfRing, 20); if (valueOfRing == aHanoi.getValueOfSelectedRing()) { g.setColor(Color.black); g.drawRect(indexOfTower * 200 + 100 - 12 * valueOfRing, 140 - indexOfRing * 20, 24 * valueOfRing - 1, 20 - 1); g.drawRect(indexOfTower * 200 + 100 - 12 * valueOfRing + 1, 140 - indexOfRing * 20 + 1, 24 * valueOfRing - 1 - 2, 20 - 1 - 2); } g.setColor(Color.black); g.drawString(Integer.toString(valueOfRing), 200 * indexOfTower + 95, 140 - 20 * indexOfRing + 16); } } } }