import javax.microedition.lcdui.Graphics; //導入方法依賴的package包/類
/**
* Draws the item.
*
* @param g Graphics context.
* @param viewX Top-left x-coordinate of the current view area (grid coordinates, not screen)
* @param viewY Top-left y-coordinate of the current view area (grid coordinates, not screen)
*/
public void paint(Graphics g, int viewX, int viewY){
if (Log.TEST) Log.note("[GridItem#paint]-->");
// Calculate actual drawing coordinates from the view coordinates
int translatedX = x - viewX;
int translatedY = y - viewY;
// First draw the underlying rectangle, and get color for text drawing
if (selected) {
g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND));
// Draw highlighted background
g.fillRect(translatedX, translatedY, width, height);
g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BORDER));
// Draw border
g.drawRect(translatedX, translatedY, width, height);
// Set color for text drawing
g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND));
} else {
//g.setColor(display.getColor(Display.COLOR_BORDER));
//g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND));
g.setColor(~display.getColor(Display.COLOR_BACKGROUND));
// Draw border
g.drawRect(translatedX, translatedY, width, height);
// Set color for text drawing
g.setColor(display.getColor(Display.COLOR_FOREGROUND));
}
drawContents(g, translatedX + V_PAD, translatedY + H_PAD,
width - 2 * H_PAD, height - 2 * V_PAD);
}