关闭

一 二 三级界面的连接 问题 (1)

106人阅读 评论(0) 收藏 举报
目前已经实现主界面与二级界面的相互连接多谢亚日的帮助  现在想让二级界面与三级界面之间相互连接  

本人刚学不久 其中中的很多原理还不是太懂  希望大家帮忙啊


主界面  
package ui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MainFace extends MIDlet implements CommandListener {
    private Display dis;

    // 按钮
    private Command cmdOption;

    private Command cmdOkcheci;

    private Command cmdOkjiudian;

    private Command cmdOkluxian;

    private Command cmdBack;

    private Command cmdExit;

    

    int index = 0;
    

    // 创建界面
    public MainFaceCanvas fc = new MainFaceCanvas();

//     private HelpCanvas hc = new HelpCanvas();

    private RouteCanvas rc;
    private HoteCanvas hc;
    private TrainNumberCanvas tnc;
    private HelpCanvas hec;
    
    public MainFace() {
        dis = Display.getDisplay(this);
        rc = new RouteCanvas(this);
        hc = new HoteCanvas(this);
        tnc = new TrainNumberCanvas(this);
        hec = new HelpCanvas(this);
        cmdOption = new Command("操作", Command.SCREEN, 1);
        cmdOkcheci = new Command("确定", Command.SCREEN, 2);
        cmdOkjiudian = new Command("确定", Command.SCREEN, 3);
        cmdOkluxian = new Command("确定", Command.SCREEN, 4);
        cmdBack = new Command("返回", Command.SCREEN, 1);
        cmdExit = new Command("退出", Command.EXIT, 1);
        

    }

    protected void startApp() throws MIDletStateChangeException {
        dis.setCurrent(fc);
    }

    protected void pauseApp() {
        this.notifyDestroyed();
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

    }

    public void commandAction(Command c, Displayable d) {
        if (c == List.SELECT_COMMAND) {

        } else if (c == cmdOption) {

        } else if (c == cmdBack) {
            dis.setCurrent(fc);

        } else if (c == cmdExit) {

            notifyDestroyed();
        } else if (c == cmdOkcheci) {

        } else if (c == cmdOkjiudian) {

        } else if (c == cmdOkluxian) {
            try {
                destroyApp(true);
            } catch (Exception e) {
            }
        }
    }

    class MainFaceCanvas extends Canvas {
        int x = this.getWidth();
        int y = this.getHeight();
        private Image img1 ;
        private Image img2 ;
        private Image img3 ;
        private Image img4;
        private Image img11 ;
        private Image img22 ;
        private Image img33 ;
        private Image img44;
        public MainFaceCanvas(){
try{
img1= Image.createImage("/01.png");
img2= Image.createImage("/02.png");
img3= Image.createImage("/03.png");
img4= Image.createImage("/04.png");
img11= Image.createImage("/011.png");
img22= Image.createImage("/022.png");
img33= Image.createImage("/033.png");
img44= Image.createImage("/044.png");
}catch(Exception ex){
ex.printStackTrace();
}
}

        public void paint(Graphics g) {
            g.setColor(69, 132, 217);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(225, 225, 225);
            g.setStrokeStyle(Graphics.SOLID);
            Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
                    Font.SIZE_LARGE);
            g.setFont(font);
            g.drawString("旅友无忧", 90, 5, Graphics.LEFT | Graphics.TOP);
            g.setColor(225, 225, 225);
            
            g.drawImage(img11,40, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img22,130, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img33,40, 150,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img44,130, 150,Graphics.TOP|Graphics.LEFT);
            
          if (index == 1){//这个界面没给出
            g.drawImage(img1,40, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img22,130, 60,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img33,40, 150,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img44,130, 150,Graphics.TOP|Graphics.LEFT);
           }
           if (index == 2){//这个界面给出
            g.drawImage(img11,40, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img2,130, 60,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img33,40, 150,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img44,130, 150,Graphics.TOP|Graphics.LEFT);
           }
           if (index == 3){//这个也没给出
            g.drawImage(img11,40, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img22,130, 60,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img3,40, 150,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img44,130, 150,Graphics.TOP|Graphics.LEFT);
           }
           if (index == 4){//这个也没给出
            g.drawImage(img11,40, 60,Graphics.TOP|Graphics.LEFT);
            g.drawImage(img22,130, 60,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img33,40, 150,Graphics.TOP|Graphics.LEFT);
               g.drawImage(img4,130, 150,Graphics.TOP|Graphics.LEFT);
           }
        }

        protected void keyPressed(int keyCode) {
            int action = this.getGameAction(keyCode);
            switch (action) {
            case Canvas.UP:
                index = 1;
                dis.setCurrent(fc);
                fc.repaint();
                break;
            case Canvas.DOWN:
                index = 2;
                
                dis.setCurrent(fc);
                fc.repaint();
                break;
            case Canvas.LEFT:
                index = 3;
                dis.setCurrent(fc);
                fc.repaint();
                break;
            case Canvas.RIGHT:
                index = 4;
                dis.setCurrent(fc);
                fc.repaint();
                break;
            case Canvas.FIRE:
                if (index == 1) {
                    rc.show();//没给出
                } else if (index == 2) {
                 tnc.show();//主要是给出的这个界面  点击来跳转到二级界面
                } else if (index == 3) {
                 hc.show();//没给出
                } else if (index == 4) {   
                 hec.show();//没给出
                }
                break;
            }
        }
    }
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1485次
    • 积分:185
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档