CalcCanvas.java~2~
上传用户:hmzjsh
上传日期:2009-12-31
资源大小:5k
文件大小:2k
- package my.calc;
- import com.nokia.mid.ui.FullCanvas;
- import javax.microedition.lcdui.*;
- import java.io.*;
- public class CalcCanvas extends FullCanvas{
- /**退出按钮*/
- private Command cmdExit;
- /**标题*/
- private String title = "Calculator";
- /**字体*/
- private Font f;
- /**显示的数字*/
- private int result = 0;
- /**焦点编号*/
- private int num = 0;
- /**图片起点坐标*/
- private int x = 20;
- private int y = 70;
- /**按钮尺寸*/
- private int buttonWidth = 38;
- private int buttonHeight = 28;
- /**图片文件*/
- private Image image = null;
- /**默认构造方法*/
- public CalcCanvas() {
- try{
- image = Image.createImage("/calc.png");
- System.out.println(x);
- }catch(IOException e){
- //ignore
- System.out.println(e);
- }
- }
- /**
- * 绘制
- * @param g 图形对象
- */
- public void paint(Graphics g) {
- f = g.getFont();
- //绘制标题
- g.drawString(title,getWidth() / 2,f.getHeight() / 2,Graphics.TOP|Graphics.HCENTER);
- //绘制文本框
- g.drawRect(3,24,172,20);
- //绘制数字
- String temp = Integer.toString(result);
- g.drawString(temp,getWidth() - temp.length() / 2 - 3,30,Graphics.TOP|Graphics.RIGHT);
- //绘制面板
- g.drawImage(image,2,50,Graphics.TOP|Graphics.LEFT);
- }
- /**
- * 事件处理
- * @param keyCode 按钮值
- */
- public void keyPressed(int keyCode){
- String keyName = getKeyName(keyCode);
- System.out.println(keyName);
- }
- /**
- * 绘制焦点矩形
- * @param g 图形对象
- * @param x X坐标
- * @param y Y坐标
- */
- public void drawFoucs(Graphics g,int x,int y){
- }
- }