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

📄 articlemidlet.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
/*
 * ArticleMIDlet.java
 *
 * Created on 2006年8月15日, 下午4:48
 */

package com.j2medev.chapter10;

import com.j2medev.chapter10.sampleservice.Article;
import com.j2medev.chapter10.sampleservice.SampleServiceSEI_Stub;
import java.rmi.RemoteException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 *
 * @author  ming
 * @version
 */
public class ArticleMIDlet extends MIDlet implements CommandListener{
    
    private Display display = null;
    private Form form = null;
    private TextField idField = new TextField("input query id:","",20,TextField.ANY);
    private Command queryCommand = new Command("query",Command.OK,1);
    private Command exitCommand = new Command("exit",Command.EXIT,1);
    public void startApp() {
        if(display == null){
            display = Display.getDisplay(this);
            form = new Form("query article");
            form.append(idField);
            form.addCommand(queryCommand);
            form.addCommand(exitCommand);
            form.setCommandListener(this);
        }
        display.setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command command, Displayable displayable) {
        if(command == exitCommand){
            destroyApp(false);
            notifyDestroyed();
        }else if(command == queryCommand){
            form.deleteAll();
            form.append("querying article please wait");
            new Thread(){
                public void run(){
                        try {
                            SampleServiceSEI_Stub service = new SampleServiceSEI_Stub();
                            int id = Integer.parseInt(idField.getString());
                            Article article = service.getArticleByID(id);
                            form.deleteAll();
                            form.append(article.getTitle()+"\n");
                            form.append(article.getContent()+"\n");
                            form.removeCommand(queryCommand);
                        } catch (NumberFormatException ex) {
                            ex.printStackTrace();
                        } catch (RemoteException ex) {
                            ex.printStackTrace();
                        }
                }
            }.start();
        }
    }
}

⌨️ 快捷键说明

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