// 7/1/10 M. Brenner import java.io.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; public class Boardisplayer implements Observer { static private final int COLS = 3, ROWS = 3, EMPTY = 0, CELLWIDTH = 120, CELLHEIGHT = 180, BOARDTOP = 0, BOARDBOTTOM = BOARDTOP + 3*CELLHEIGHT; static private final String SYMBOLFILE = "symbols.png"; private int height_, width_; private TiledLayer layer_; public Boardisplayer (int width, int height) { int col, row, tileid; Image image; width_ = width; height_ = height; try { image = Services.makeimage (SYMBOLFILE); layer_ = new TiledLayer (COLS, ROWS, image, CELLWIDTH, CELLHEIGHT); } catch (IOException e) { Log.print ("Boardisplayer.ctor() error: " + e); } } public int calcol (int x) { return x/CELLWIDTH; } public int calcrow (int y) { return y/CELLHEIGHT; } public void clear() { int col, row; for (row = 0; row < ROWS; row++) { for (col = 0; col < COLS; col++) { clear (row, col); } } } public void clear (int row, int col) { layer_.setCell (col, row, EMPTY); } public int getbottom() { return BOARDBOTTOM; } public int getop() { return BOARDTOP; } public Layer getlayer() { return layer_; } public void mark (int row, int col, int symbol) { layer_.setCell (col, row, symbol); } public void update (Observable obs, Object arg) { int col, row; Board board; board = (Board) obs; for (row = 0; row < ROWS; row++) { for (col = 0; col < COLS; col++) { mark (row, col, board.getelement (row, col)); } } Application.getappgui().refresh(); } }