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

📄 manager.java

📁 为解压缩文件
💻 JAVA
字号:

package com.j2medev.numbergame;
import java.util.*;
import javax.microedition.lcdui.*;

// A subclass of Area that can act as
// the parent for other components.

public class Manager extends Area
{
    protected Vector children = new Vector();

    protected Area focus = null;

    public Manager()
    {
        super(0, 0, 0, 0, null);
        w = getCanvasWidth();
        h = getCanvasHeight();
    }

    public void add(Area child)
    {
        if (!children.contains(child))
        {
            children.addElement(child);
            child.setParent(this);
            repaintArea(child, false);
        }
    }

    protected Area getFocus()
    {
        if (focus == null && children.size() > 0)
        {
            focus = (Area) children.elementAt(0);
        }

        return focus;
    }

    public void keyPressed(int keyCode)
    {
        Area focus = getFocus();
        if (focus != null && focus != this)
        {
            focus.keyPressed(keyCode);
        }
    }

    public void keyReleased(int keyCode)
    {

    }

    public void keyRepeated(int keyCode)
    {

    }

    // Called to move the focus to the next
    // or previous component

    protected void moveFocus(boolean forward)
    {
        Area oldFocus = getFocus();
        if (oldFocus != null)
        {
            int i = children.indexOf(oldFocus);
            int last = children.size() - 2;
            if (forward)
            {
                if (++i > last)
                    i = 0;
            } else
            {
                if (--i < 0)
                    i = last;
            }

            focus = (Area) children.elementAt(i);
            repaintArea(oldFocus, false);
            repaintArea(focus, true);
        }
    }

    public void remove(Area child)
    {
        if (children.removeElement(child))
        {
            child.setParent(null);
            repaintArea(child, false);
        }
    }

    protected void paint(Graphics g)
    {
        if (focus == null)
            getFocus();

        eraseBackground(g);
        g.setColor(getForeColor());

        int n = children.size();
        for (int i = n - 1; i >= 0; --i)
        {
            try
            {
                Area area = (Area) children.elementAt(i);
                area.paint(g, (focus == area));
            } catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }

    protected void paintArea(Graphics g, boolean hasFocus)
    {
    }
}

⌨️ 快捷键说明

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