import java.awt.*; import javax.swing.*; class Cell { // paint a cell starting at x and y public void paint (Graphics g, int x, int y) { g.setColor(Color.yellow); g.fillRect(x, y, CellWidth, CellHeight); } public final static int CellWidth = 10; public final static int CellHeight = 10; } class Lolo extends Cell { public void paint (Graphics g, int x, int y) { g.setColor(Color.red); g.fillRect(x, y, CellWidth, CellHeight); } } class LoloGame extends JFrame { public static void main (String [ ] args) { LoloGame world = new LoloGame(); world.show(); } public LoloGame () { // awt initialization setTitle("Lolo Game"); setSize(20 + BoardWidth * Cell.CellWidth, 40 + BoardHeight * Cell.CellHeight); // game specific initialization for (int i = 0; i < BoardWidth; i++) for (int j = 0; j < BoardHeight; j++) board[i][j] = new Cell(); board[loloX][loloY] = lolo; } private static final int BoardWidth = 30; private static final int BoardHeight = 20; protected static Cell [ ] [ ] board = new Cell[BoardWidth][BoardHeight]; private int loloX = 10; private int loloY = 10; private Lolo lolo = new Lolo(); public void paint (Graphics g) { for (int i = 0; i < BoardWidth; i++) for (int j = 0; j < BoardHeight; j++) board[i][j].paint(g, 10 + Cell.CellWidth * i, 30 + Cell.CellHeight * j); } }