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

📄 messageui.java

📁 一个可以连接gps的程序
💻 JAVA
字号:
package GPSreader;

import javax.microedition.lcdui.*;
import java.util.*;

public class MessageUI extends Canvas
{
    public Vector msgs = new Vector();
    private int messageidx = 0;
    private int w, h, fontH;
    public Font font;
    private int x0=0, y0=0;
    public int bookmarkId = 1;
    public int backTo = 0;
    
    public MessageUI(btGPSreader host)
    {
        addCommand(new Command("Search", Command.SCREEN, 1));
        addCommand(new Command("Stop", Command.STOP, 2));
        addCommand(new Command("Exit", Command.EXIT, 3));
        setCommandListener(host);
    }
    
    public void paint(Graphics g) 
    {
        if ( font == null )
        {
            // cache the font and width,height value
            // when it is used the first time
            font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
            w = this.getWidth();
            h = this.getHeight();
            fontH = font.getHeight();
        }
        // detemine midx based on the screen height and number of message
        /*
        midx = msgs.size() - (h/fh) ;
        if ( midx < 0 )
          midx = 0;
            */
        int y = fontH; // 1st line y value

        // message will be rendered in black color, on top of white backgound
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, w, h);
        g.setColor(0, 0, 0);
        g.setFont(font);
        g.translate(-x0, -y0);

        // render the messages on screen
        for ( int i= messageidx; i< msgs.size(); i++ )
        {
            String s = (String)msgs.elementAt(i);
            g.drawString( s, 0, y, Graphics.BASELINE | Graphics.LEFT );
            y += fontH;
        }
    }
    
    protected  void keyPressed(int key) 
    {
        if ( getGameAction( key ) == Canvas.RIGHT )
        {
            x0+=50;
        } 
        else if ( getGameAction( key ) == Canvas.LEFT )
        {
            x0-=50;
        } 
        else if ( getGameAction( key ) == Canvas.UP )
        {
            // note: change this from 50 to 100 if you want to scroll faster
            y0-=50;
        } 
        else if ( getGameAction( key ) == Canvas.DOWN )
        {
            // note: change this from 50 to 100 if you want to scroll faster
            y0+=50;
        }
        repaint();
    }
    
    public void clear()
    {
        msgs.removeAllElements();
        messageidx = 0;
        x0 = 0;
        y0 = 0;
        bookmarkId = 1;
        repaint();
    }
    
    public void add( String s )
    {
        msgs.addElement( s );
        repaint();
    }
}

⌨️ 快捷键说明

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