700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > drawrect java_Java Graphics.drawRect方法代码示例

drawrect java_Java Graphics.drawRect方法代码示例

时间:2020-09-22 00:49:33

相关推荐

drawrect java_Java Graphics.drawRect方法代码示例

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);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。