Chinaunix首页 | 论坛 | 博客
  • 博客访问: 223942
  • 博文数量: 45
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 915
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-18 16:03
文章分类

全部博文(45)

文章存档

2011年(1)

2008年(44)

我的朋友

分类: Java

2008-07-16 13:48:56

附图:


import javax.microedition.lcdui.*;

public class MainCanvas extends Canvas {
    Graphics g;

    public Font m_aFont;

    int start_x = 0;

    int start_y = 0;

    int end_x = 0;

    int end_y = 0;

    private String str1 = "GRPS";

    private String str2 = "WIFI";

    private String message = null;

    boolean result = false;

    boolean s = true;

    public MainCanvas() {
        // m_aFont //分配数组大小


        // 存储各种字体,如果创建新字体失败,则存储系统默认字体


        try {
            m_aFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
                    Font.SIZE_LARGE);
        } catch (Exception e) {
            m_aFont = Font.getDefaultFont();
        }
        message = str1;
    }

    protected void paint(Graphics g) {
        // 清屏


        g.setColor(0x00000000);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(0x00FF0000);
        
        //标题


        String str = "**智能终端掌上控制平台";
        g.setFont(m_aFont);
        g.drawString(str, this.getWidth() / 2, 20, Graphics.HCENTER
                | Graphics.BOTTOM);

        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                Font.SIZE_LARGE));
        g.setColor(255, 255, 255);
        //左三角


        g.fillTriangle(20, 25, 20, 55, 0, 40);
        g.drawLine(20, 25, 220, 25);
        //直线


        g.drawString(message, this.getWidth() / 2, 50, Graphics.HCENTER
                | Graphics.BOTTOM);
        //直线


        g.drawLine(20, 55, 220, 55);

        //右三角


        g.fillTriangle(220, 25, 220, 55, this.getWidth(), 40);

        this.drawMenu(g, 6);

    }

    protected void Menu1(Graphics g, String message) {
        //g.setColor(255, 255, 255);


        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                Font.SIZE_LARGE));
        g.drawString(message, this.getWidth() / 2, 50, Graphics.HCENTER
                | Graphics.BOTTOM);
    }

    protected void Menu2(Graphics g) {
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                Font.SIZE_LARGE));
        g.drawString(str2, this.getWidth() / 2, 50, Graphics.HCENTER
                | Graphics.BOTTOM);
    }

    public void pointerPressed(int x, int y) {
        start_x = x;
        start_y = y;
        if (start_x > 5 && start_x < 20 && start_y > 25 && start_y < 55) {
            if (message == str1) {
                message = str2;
            } else {
                message = str1;
        
            }
        }
        if (start_x > this.getWidth() - 20 && start_x < 250
                && start_y > 25 && start_y < 50) {
            if (message == str2) {
                message = str1;
            } else {
                message = str2;
            }
        }
        repaint();
        this.serviceRepaints();

    }
    public void keyPressed(int keycode) {
        int action = this.getGameAction(keycode);
        switch (action) {
        case Canvas.FIRE:
            result = true;
            this.repaint();
            break;

        case Canvas.LEFT:
            result = true;
            this.repaint();
            break;

        case Canvas.RIGHT: {
            result = true;
            this.repaint();
            break;
        }
        default:
            break;
        }

        // repaint();


        this.serviceRepaints();
        // servicerepaints();


    }
    

    private void drawMenu(Graphics graphics, int number) {
        // 要传进来的Graphics,菜单宽,菜单间隔,菜单项目数


        /**
         * 内部值,可以释放,方便修改
         */

        Graphics g;
        int num;

        g = graphics;
        num = number;
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                Font.SIZE_LARGE));
        switch (num) {
        case 6:
            g.drawString("您可以选择任何一种通讯方式(联网方式", 0, 90, Graphics.TOP
                    | Graphics.LEFT);

        case 5:
            g.drawString("必须与手机本身设置一致);", 0, 110, Graphics.TOP | Graphics.LEFT);

        case 4:
            g.drawString("WIFI模式:无需使用(需无线路由器支持),", 0, 140, Graphics.TOP
                    | Graphics.LEFT);

        case 3:
            g.drawString("连接互联网速度快.", 0, 160, Graphics.TOP | Graphics.LEFT);

        case 2:
            g.drawString("GPRS模式:模式经济(可包月),连接互联网", 0, 190, Graphics.TOP
                    | Graphics.LEFT);

        case 1:
            g.drawString("速度稳定.", 0, 210, Graphics.TOP | Graphics.LEFT);

        default:
            break;
        }
        
        //flushGraphics();



    }

}

 

阅读(1054) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~