DiamondItem.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- public class DiamondItem
- extends CustomItem {
- private boolean mState;
- public DiamondItem(String title) {
- super(title);
- mState = false;
- }
- public void toggle() {
- mState = !mState;
- repaint();
- }
- // CustomItem abstract methods.
- public int getMinContentWidth() { return 80; }
- public int getMinContentHeight() { return 40; }
- public int getPrefContentWidth(int width) {
- return getMinContentWidth();
- }
- public int getPrefContentHeight(int height) {
- return getMinContentHeight();
- }
- public void paint(Graphics g, int w, int h) {
- g.drawRect(0, 0, w - 1, h - 1);
- int stepx = 8, stepy = 16;
- for (int y = 0; y < h; y += stepy) {
- for (int x = 0; x < w; x += stepx) {
- g.drawLine(x, y, x + stepx, y + stepy);
- g.drawLine(x, y + stepy, x + stepx, y);
- if (mState == true) {
- int midx = x + stepx / 2;
- int midy = y + stepy / 2;
- g.fillTriangle(x, y, x + stepx, y, midx, midy);
- g.fillTriangle(midx, midy, x, y + stepy,
- x + stepx, y + stepy);
- }
- }
- }
- }
- // CustomItem methods.
- protected void keyPressed(int keyCode) { toggle(); }
- protected void pointerPressed(int x, int y) { toggle(); }
- }