import java.awt.*; public class StoneFieldView extends Canvas { int x, y; double part = 1.0; public StoneFieldView(int x, int y) { super(); this.x = x; this.y = y; } protected final StoneView parentView() { return (StoneView) getParent(); } public void update(Graphics g) { if (part >= 1.0) setBackground(Color.black); else { int side = parentView().getModel().getSum(x, y); if (side < 0) setBackground(new Color(64, 0, 0)); if (side > 0) setBackground(new Color(0, 0, 64)); } super.update(g); } protected final Color getShade(int i, int side) { int c = 127 / shades * i + 128; if (side < 0) return new Color(c, 0, 0); if (side > 0) return new Color(0, 0, c); return new Color(c, c, c); } public void paint(Graphics g) { int cx = bounds().width / 2; int cy = bounds().height / 2; int step = (int) (Math.min(cx, cy) / shades / 3 * part); for (int i = 0; i < shades; i++) { g.setColor(getShade(i, parentView().getModel().getSum(x, y))); int t = (shades - i) * step; if (parentView().getModel().isRockOn(x, y)) g.fillOval(cx - t * 2, cy - t * 2, t * 4, t * 4); else g.fillRect(cx - t, cy - t, t * 2, t * 2); }; if (part < 1.0) { part += 0.25; repaint(50); }; } public int getX() { return x; } public int getY() { return y; } public void dirty(boolean boom) { if (boom) part = 0.25; repaint(200); } public Dimension preferredSize() { return new Dimension(30, 30); } public Dimension minimumSize() { return new Dimension(10, 10); } static final int shades = 3; }