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

📄 bgtask.java

📁 在手机上 可以 存取数据 删除 数据 一个简单的手机应用
💻 JAVA
字号:

import javax.microedition.lcdui.*;

public abstract class BgTask extends Thread implements Cancelable {

    ProcObserver m_poUI;
    protected Displayable m_prevScreen;
    protected Displayable m_nextScreen;
    protected boolean needAlert;
    protected Alert alertScreen;
    private Display m_dis;
    public String m_failTitle;
    public String m_failCtnt;
 
    public abstract boolean runTask();

    public BgTask(ProcObserver m_poUI,Displayable prev,Displayable next,Display dis) {
        this.m_poUI = m_poUI;
        this.m_prevScreen = prev;
        this.m_nextScreen = next;
        this.m_dis = dis;
        this.needAlert = false;
        m_failTitle = "";
        m_failCtnt = "";
      
    }

    public void run() {

        boolean taskComplete=false;
        try {
            taskComplete=runTask();
        } catch (Exception e) {
            Alert al = new Alert("发生了异常", e.getMessage(), null,AlertType.ALARM);
            al.setTimeout(Alert.FOREVER);
            m_dis.setCurrent(al);
        } finally {
            if(taskComplete){
                 m_dis.setCurrent(m_nextScreen);
            }else{
                m_dis.setCurrent(new Alert(m_failTitle,m_failCtnt, null,AlertType.ALARM),m_prevScreen);
            }

            m_poUI.exit();
        }
    }


    public static void runWithProgressGauge(BgTask btask,String title,String prompt,boolean stoppable,Display dis) {
    
        ProcObserver po = btask.getProcObserver();
        po.reset();
        po.setStoppable(stoppable);

        if(stoppable){
            po.setCancelalbeObject(btask);
        }

        po.setTitle(title);
        po.setPrompt(prompt);
       
     po.show(dis);
        btask.start();
    }

    public ProcObserver getProcObserver() {
        return m_poUI;
    }
}






⌨️ 快捷键说明

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