?? smileyitem.java
字號:
import javax.microedition.lcdui.*;
public class SmileyItem extends CustomItem
{
// the state of the item; true for happy, false for sad
private boolean isHappy;
public SmileyItem(String title)
{
super(title);
isHappy = true;
}
public void change()
{
isHappy = !isHappy;
repaint();
}
// overide abstract methods to fill in size details for the item
public int getMinContentWidth() { return 50; }
public int getMinContentHeight() { return 20; }
public int getPrefContentWidth(int width) { return getMinContentWidth(); }
public int getPrefContentHeight(int height) { return getMinContentHeight(); }
// where responsible for drawing the item onto a supplied graphics canvas
// for our custom smiley we just draw a red bax and some text.
public void paint(Graphics g, int w, int h)
{
// set color to red
g.setColor(0xff0000);
// fill the item area
g.fillRect(0, 0, w - 1, h - 1);
// change to white
g.setColor(0xffffff);
// set the font
g.setFont(Font.getDefaultFont());
// draw the smiley using text
g.drawString(":" + (isHappy ? ")" : "("), getMinContentWidth()/2, 1,
Graphics.TOP | Graphics.HCENTER);
}
// with a custom item we have to handle all the input ourselves, in this
// case we just change the state of the smiley so matter what they hit
protected void keyPressed(int keyCode)
{
change();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -