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

📄 countercanvas.java

📁 J2me分析工具
💻 JAVA
字号:

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.rms.*;

public class CounterCanvas extends Canvas implements CommandListener
{

    private RMSModel model;
    private RMSAnalyzer RMSanalyzer;
    private int interTime;
    private int counter;
    private boolean go = true;
    public static Command exitCommand = new Command("退出", Command.EXIT, 3);
    public static final int INC = 1;
    public TimerTask timerTask;
    public final Timer timer = new Timer();

    public CounterCanvas(int interTime, int base, RMSAnalyzer rmsa)
            throws RecordStoreException
    {
        this.interTime = interTime;
        this.counter = base;
        this.RMSanalyzer = rmsa;
        model = new RMSModel(base, RMSanalyzer);
        this.addCommand(exitCommand);
        this.setCommandListener(this);

        timerTask = new TimerTask()
        {
            public void run()
            {

                try
                {
                    model.writeRecord(INC);
                    counter++;
                } catch (RecordStoreFullException e)
                {
                    go = false;
                    model.deleteRMS();
                    timer.cancel();
                } catch (RecordStoreException e)
                {
                    model.deleteRMS();
                    RMSanalyzer.showAlertError(e.getMessage());
                    timer.cancel();
                }
                repaint();

            }
        };

    }

    public void start()
    {
        timer.schedule(timerTask, 500, interTime);
    }

    public void setCounter(int counter)
    {
        this.counter = counter;
    }

    public void setInterTime(int interTime)
    {
        this.interTime = interTime;
    }


    protected void paint(Graphics arg0)
    {
        
        int SCREEN_WIDTH = this.getWidth();
        int SCREEN_HEIGHT = this.getHeight();
        arg0.drawRect(SCREEN_WIDTH / 10, SCREEN_HEIGHT / 2,
                SCREEN_WIDTH * 4 / 5, 10);
        if (RMSanalyzer.getDisplay().isColor())
        {
            arg0.setColor(128, 128, 255);
        }
        arg0.fillRect(SCREEN_WIDTH / 10 + 1, SCREEN_HEIGHT / 2 + 1, counter, 9);
        if (!go)
            arg0.drawString("最大值:" + counter + "K字节", SCREEN_WIDTH / 10,
                    SCREEN_HEIGHT / 10, Graphics.TOP | Graphics.LEFT);

    }

    public void commandAction(Command arg0, Displayable arg1)
    {
        
        if (arg0 == exitCommand)
        {
            RMSanalyzer.exitMIDlet();
        }

    }

}

⌨️ 快捷键说明

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