程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> 高級界面實現頁面之間的跳轉

高級界面實現頁面之間的跳轉

編輯:J2ME
高級界面實現頁面之間的跳轉 作者:leilu200…    文章來源:leilu2008    更新時間:2007-10-2 10:08:27 230 package test;

import Java.io.IOException;

import Javax.microedition.lcdui.Command;
import Javax.microedition.lcdui.CommandListener;
import Javax.microedition.lcdui.Display;
import Javax.microedition.lcdui.Displayable;
import Javax.microedition.lcdui.Image;
import Javax.microedition.lcdui.List;
import Javax.microedition.midlet.MIDlet;
import Javax.microedition.midlet.MIDletStateChangeException;

/** *//**
 * 
 * @author leilu
 * 
 */
public class MainPage extends MIDlet implements CommandListener
...{
    // m_cmdExit
    private Command m_cmdExit = null;

    // m_cmdOK
    private Command m_cmdOK = null;

    // Display
    private Display display = null;

    // list
    private List list = null;

    //
    private Image icon = null;

    public MainPage()
    ...{
        super();

    }

    protected void startApp() throws MIDletStateChangeException
    ...{
        // display
        display = Display.getDisplay(this);
        // m_cmdExit
        m_cmdExit = new Command("Exit", Command.EXIT, 1);
        // m_cmdOK
        m_cmdOK = new Command("OK", Command.OK, 1);
        // 創建圖像
        try
        ...{
            icon = Image.createImage("/Icon.png");
        }
        catch (IOException e)
        ...{
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // list
        list = new List("主界面", List.EXCLUSIVE);
        list.append("FirstPage", icon);
        list.append("Secondpage", icon);
        // 增加按鈕
        list.addCommand(m_cmdExit);
        list.addCommand(m_cmdOK);
        // 監聽
        list.setCommandListener(this);
        // 顯示
        display.setCurrent(list);

    }

    protected void pauseApp()
    ...{

    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException
    ...{
    }

    public void commandAction(Command c, Displayable d)
    ...{
        String cmd = c.getLabel();
        if (cmd == "OK")
        ...{
            switch (((List) d).getSelectedIndex())
            ...{
            case 0:
                FirstPage first = new FirstPage(display, list);
                display.setCurrent(first);
                break;
            case 1:
                SecondPage second = new SecondPage(display, list);
                display.setCurrent(second);
            default:
                break;
            }
        }
        else if (cmd == "Exit")
        ...{
            try
            ...{
                destroyApp(false);
            }
            catch (MIDletStateChangeException e)
            ...{
                e.printStackTrace();
            }
            notifyDestroyed();

        }
    }

}
  package test;

import Java.io.IOException;

import Javax.microedition.lcdui.Command;
import Javax.microedition.lcdui.CommandListener;
import Javax.microedition.lcdui.Display;
import Javax.microedition.lcdui.Displayable;
import Javax.microedition.lcdui.Form;
import Javax.microedition.lcdui.Image;
import Javax.microedition.lcdui.List;
import Javax.microedition.lcdui.Ticker;

public class FirstPage extends Form implements CommandListener
...{
    // TICKER_TEXT滾動文字
    private static final String TICKER_TEXT = "這是一個滾動條的例子正在滾動,可以一直滾動除非有觸發了停止事件";

    // display
    private Display display;
    //
    private Ticker ticker = null;

    // m_cmdBack
    private Command m_cmdBack = null;
    //list
    private List list= null;

    public FirstPage(Display display,Displayable list)
    ...{
        super("FirstPage");
        //
        this.list = (List)list;
        this.display= display;
        m_cmdBack = new Command("Back", Command.BACK, 1);
        ticker = new Ticker(TICKER_TEXT);
        this.setTicker(ticker);
        //增加圖片
        Image icon = null;
        try
        ...{
            icon = Image.createImage("/Java.png");
        }
        catch (IOException e)
        ...{
            e.printStackTrace();
        }
        this.append(icon);
        //增加按鈕
        this.addCommand(m_cmdBack);
        this.setCommandListener(this);
        //顯示FirstPage
        display.setCurrent(this);

    }

    public void commandAction(Command c, Displayable d)
    ...{
        if (m_cmdBack == c)
        ...{
            display.setCurrent(list);
        }

    }

}

 

package test;

import Javax.microedition.lcdui.Alert;
import Javax.microedition.lcdui.AlertType;
import Javax.microedition.lcdui.Command;
import Javax.microedition.lcdui.CommandListener;
import Javax.microedition.lcdui.Display;
import Javax.microedition.lcdui.Displayable;
import Javax.microedition.lcdui.Form;
import Javax.microedition.lcdui.List;
import Javax.microedition.lcdui.TextFIEld;
public class SecondPage extends Form implements CommandListener
...{
    // display
    private Display display;

    // Back
    private Command m_cmdBack;

    // Alert
    private Command m_cmdAlert;

    // list
    private List list = null;

    public SecondPage(Display display, Displayable list)
    ...{
        super("Second");
        this.display = display;
        this.list = (List) list;
        //
        m_cmdBack = new Command("Back", Command.BACK, 1);
        m_cmdAlert = new Command("Alert", Command.SCREEN, 1);
        this.append(new TextFIEld("E_mail", "[email protected]", 15,
                TextFIEld.EMAILADDR));
        // 增加按鈕
        this.addCommand(m_cmdBack);
        this.addCommand(m_cmdAlert);
        this.setCommandListener(this);
        // 顯示Form屏幕
        display.setCurrent(this);
    }

    public void commandAction(Command c, Displayable d)
    ...{
        if (m_cmdAlert == c)
        ...{
            // 創建要顯示的圖標

            // 創建一個Alert屏幕對象,要顯示的圖標為 img
            Alert info = new Alert("This is a Alert Example");
            info.setType(AlertType.INFO);

            // 設置顯示時間
            // info.setTimeout(Alert.FOREVER);
            info.setTimeout(3000);
            // 顯示Alert屏幕
            display.setCurrent(info);
        }
        if (m_cmdBack == c)
        ...{
            display.setCurrent(list);
        }

    }

}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved