counteritem.java

来自「J2ME手机游戏开发技术详解随书光盘」· Java 代码 · 共 90 行

JAVA
90
字号
import javax.microedition.lcdui.*;

// A custom component for MIDP 2.0 that wraps
// a CounterArea instance.

public class CounterItem extends CustomItem
                         implements CounterArea.Callback {

    public CounterItem(){
        super( null );

        _area = new CounterArea();
        _area.setCallback( this );
    }

    public Font getFont(){
        return _area.getFont();
    }

    public int getMinContentHeight(){
        return _area.getMinHeight();
    }

    public int getMinContentWidth(){
        return _area.getMinWidth();
    }

    public int getPrefContentHeight( int width ){
        return getMinContentHeight();
    }

    public int getPrefContentWidth( int height ){
        return getMinContentWidth();
    }

    public int getValue(){
        return _area.getValue();
    }

    protected void hideNotify(){
        _area.stop();
    }

    public void invalidateCounter( CounterArea counter ){
        if( counter == _area ){
            invalidate();
        }
    }

    protected void paint( Graphics g, int width, int height ){
        _area.paint( g );
    }

    public void repaintCounter( CounterArea counter ){
        if( counter == _area ){
            repaint();
        }
    }

    public void resizeCounter( CounterArea counter ){
        if( counter == _area ){
            invalidate();
        }
    }

    protected void sizeChanged( int w, int h ){
        _area.setWidth( w );
        _area.setHeight( h );
    }

    public void setFont( Font f ){
        _area.setFont( f );
    }

    public void setValue( int value ){
        _area.setValue( value );
    }

    protected void showNotify(){
        _area.start();
    }

    public boolean traverse( int dir, int vw, int vh,
                             int[] vrect ){
        return false;
    }

    private CounterArea _area;
}

⌨️ 快捷键说明

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