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

📄 uicontroller.java

📁 <j2me 开发精解> 詹建光著 里所有的源码。对J2me的开发相当有帮助
💻 JAVA
字号:
package com.j2medev.ch5.post.ui;

import com.j2medev.ch5.post.HttpPOST;
import com.j2medev.ch5.post.model.ModelFacade;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import com.j2medev.ch5.post.share.ApplicationException;
import com.j2medev.ch5.post.model.Article;

public class UIController {
  
    private ModelFacade facade = null;
    private HttpPOST midlet = null;
    private Display display = null;
    private PostArticleUI postArticle= null;
    private ArticleContentUI articleContent = null;
    private MainMenuUI main = null;
    
    public static class EventID{
        public static final int POST_ARTICLE = 1;
        public static final int INPUT_CONTENT = 2;
        public static final int CONTENT_BACK_POST = 3;
        public static final int MAIN_POST_ARTICLE = 4;
    }
    public UIController(HttpPOST midlet) {
        this.midlet = midlet;
        display = Display.getDisplay(midlet);
    }
    
    public void init(ModelFacade facade){
        this.facade = facade;
        postArticle = new PostArticleUI(this);
        articleContent = new ArticleContentUI(this);
        main = new MainMenuUI(this);
        display.setCurrent(main);
    }
    
    public void handleEvent(final int ID,Object[] obj){
   
            switch(ID){
                case EventID.MAIN_POST_ARTICLE:{
                    display.setCurrent(postArticle);
                    break;
                }
                case EventID.INPUT_CONTENT:{
                    String title = (String)obj[0];
                    String author = (String)obj[1];
                    articleContent.init(author, title);
                    display.setCurrent(articleContent);
                    break;
                }
                case EventID.CONTENT_BACK_POST:{
                    display.setCurrent(postArticle);
                    break;
                }
                case EventID.POST_ARTICLE:{
                     final Article article = (Article)obj[0];
                    new Thread(){
                        public void run(){
                            try{
                                facade.postArticle(article);
                                Alert alert = new Alert("完成信息", "添加文章成功", null, AlertType.CONFIRMATION);
                                alert.setTimeout(2000);
                                display.setCurrent(alert, main);
                            }catch(ApplicationException ex){
                                //处理异常
                            }
                        }
                    }.start();
                    break;
                }
                default:
                    break;
            }
    }
}

⌨️ 快捷键说明

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