⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actioncanvas.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
package com.j2medev.chapter3;

import java.util.*;
import javax.microedition.lcdui.*;

public class ActionCanvas extends Canvas{
    
    private Timer timer = new Timer();
    private int x = 0;
    private String message = "hello word";
    private int direction = 1;
    private Log log = null;
    
    public ActionCanvas(Log _log) {
        log = _log;
        x = getWidth()/2;
        final int length = Font.getDefaultFont().stringWidth(message);
        timer.schedule(new TimerTask() {
            public void run() {
                if(x<10||(x+length)>getWidth()-10){
                    direction = -direction;
                }
                x = x + direction*3;
                repaint();
            }
            
        },1000,12000);
    }
    
    public void paint(Graphics g){
        int color = g.getColor();
        g.setColor(0xFFFFFF);
        g.fillRect(0,0,getWidth(),getHeight());
        g.setColor(color);
        
        g.drawString(message,x,getHeight()/2,Graphics.LEFT|Graphics.TOP);
        log.log("paint is called");
    }
    
    public void showNotify(){
        log.log("showNotify is called");
    }
    
    public void hideNotify(){
        log.log("hideNotify is called");
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -