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

📄 area.java

📁 为解压缩文件
💻 JAVA
字号:
package com.j2medev.numbergame;

import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;

//A root class for Canvas-based components.
//Because Area extends Canvas, you can actually
//use a component directly as a Canvas, although
//it's recommended you place it on Manager.

public abstract class Area extends FullCanvas
{
    protected int x;

    protected int y;

    protected int w;

    protected int h;

    protected Font font;

    protected Manager parent;

    protected int backcolor = -1;

    protected int forecolor = -1;

    protected Area(int x, int y, int w, int h)
    {
        this(x, y, w, h, null);
    }

    protected Area(int x, int y, int w, int h, Font f)
    {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        this.font = f;
    }

    // Erase the background using backcolor

    protected void eraseBackground(Graphics g)
    {
        g.setColor(getBackColor());

        if (parent == null)
        {
            g.fillRect(0, 0, getCanvasWidth(), getCanvasHeight());
        } else
        {
            g.fillRect(0, 0, w, h);
        }
    }

    public final int getBackColor()
    {
        if (backcolor == -1)
        {
            if (parent != null)
            {
                return parent.getBackColor();
            }

            backcolor = 0xFFFFFF;
        }

        return backcolor;
    }

    protected final int getCanvasHeight()
    {
        return super.getHeight();
    }

    protected final int getCanvasWidth()
    {
        return super.getWidth();
    }

    public final int getHeight()
    {
        return h;
    }

    public final int getWidth()
    {
        return w;
    }

    public final int getX()
    {
        return x;
    }

    public final int getY()
    {
        return y;
    }

    public final Font getFont()
    {
        if (font == null)
        {
            if (parent != null)
            {
                return parent.getFont();
            }

            font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                    Font.SIZE_SMALL);
            ;

        }

        return font;
    }

    public final int getForeColor()
    {
        if (forecolor == -1)
        {
            if (parent != null)
            {
                return parent.getForeColor();
            }

            forecolor = 0;
        }

        return forecolor;
    }

    public Manager getParent()
    {
        return parent;
    }

    public void keyPressed(int keyCode)
    {
    }

    public void keyReleased(int keyCode)
    {
    }

    public void keyRepeated(int keyCode)
    {
    }

    protected void moveFocus(boolean forward)
    {
        if (parent != null)
        {
            parent.moveFocus(forward);
        }
    }

    // If the area is acting like a Canvas, call
    // the real paint routine

    protected void paint(Graphics g)
    {

        eraseBackground(g);
        g.setColor(getForeColor());
        g.setFont(getFont());
        paintArea(g, true);
    }

    // The manager calls this paint routine on each of
    // its children

    public final void paint(Graphics g, boolean hasFocus)
    {
        int cx = g.getClipX();
        int cy = g.getClipY();
        int ch = g.getClipHeight();
        int cw = g.getClipWidth();
        Font f = g.getFont();
        int col = g.getColor();

        eraseBackground(g);

        g.setClip(x, y, w, h);
        g.setFont(getFont());
        g.setColor(getForeColor());

        paintArea(g, hasFocus);

        g.setClip(cx, cy, cw, ch);
        g.setFont(f);
        g.setColor(col);
    }

    // Subclass implements to do actual painting

    protected abstract void paintArea(Graphics g, boolean hasFocus);

    // Repaint the area of the given child

    public void repaintArea(Area child, boolean now)
    {
        if (parent != null)
        {
            parent.repaintArea(child, now);
        } else
        {
            repaint(child.getX(), child.getY(), child.getWidth(), child
                    .getHeight());

            if (now)
            {
                serviceRepaints();
            }
        }
    }

    public void setBackColor(int col)
    {
        backcolor = col;
    }

    public void setForeColor(int col)
    {
        forecolor = col;
    }

    protected void setParent(Manager parent)
    {
        this.parent = parent;
    }

}

⌨️ 快捷键说明

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