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

📄 sdainputpanel.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.event.PointerEvent;import cn.sda.pinyin.InputInterface;import cn.sda.pinyin.Spell2Chars;import java.util.Hashtable;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Font;/** * * @author Administrator */public class SDAInputPanel extends SDABaseControl {    //类型    public static final int imNone = 0;    public static final int imUpperCase = 1;    public static final int imLowerCase = 2;    public static final int imDigit = 3;    public static final int imPoint = 4;    public static final int imSymbol = 5;    public static final int imPinYin = 6;    //输入法类型    protected int ImeType = imPinYin;    //颜色    private int borderColor = SDAConsts.clBlack;    //选中颜色    private int selectedBackColor = SDAConsts.clBlack;    private int selectedForeColor = SDAConsts.clWhite;    //当前行位置    private int curHeight = 0;    //是否打开全角    private boolean SBCCase = false;    //输入显示    protected inputCharsPanel charsPanel = null;    //点的位置()    private int charXPos = -1;    private int charYPos = -1;    //当前被选中的Char内容(可见)    protected char selectedChar = 0;    //功能键名字    //private String funcKeyName="";    //graphic    private Graphics gg = null;    //拼音处理    //输入的字母(包括拼音,非触摸屏下的字母(字母和数字靠输入法类型区分))    protected StringBuffer inputChars;    //选择的内容(包括拼音或者非触摸屏下的字母等)    private StringBuffer selectedChars;    //对应一个拼音组合的所有汉字    protected char[] hanziChars;    //选择的汉字index    protected int selectedHanziIndex = 0;    //查询到的汉字数    private int hanziCount = 0;    //大写字母    private char[] UpperCaseChars = null;    private char[] SBCUpperCaseChars = null;    //小写字母    private char[] LowerCaseChars = null;    private char[] SBCLowerCaseChars = null;    //数字    private char[] DigitChars = null;    private char[] SBCDigitChars = null;    //标点    private char[] PointChars = null;    private char[] SBCPointChars = null;    //符号    private char[] SymbolChars = null;    private char[] SBCSymbolChars = null;    //对于一键多字母的切换处理    private Hashtable hashLowerKeyChars = null;    private Hashtable hashUpperKeyChars = null;    //获取的一键多字母的所有字母组合    protected char[] numChars = null;    //这些字母的选择的index    private int charIndex = 0;    //输入内容显示和选择框    protected class inputCharsPanel extends SDABaseControl {        //光标在屏幕中的绝对位置        protected int oraX = 0,  oraY = 0;        private int pageScrollBarColor = SDAConsts.clBtnFace;        private int pageScrollBarFontColor = SDAConsts.clBlack;        private int inputBarColor = SDAConsts.clWhite;        //选择        private int selectedBackColor = SDAConsts.clFocusShadow;        private int selectedFontColor = SDAConsts.clWhite;        //当前页        private int pageNo = 1;        //总页        private int pageCount = 1;        //输入内容焦点位置(拼音才有)        public int cursorPos = 0;        //输入状态(拼音)        protected boolean isInput = true;        public inputCharsPanel() {            super();            setVisible(false);            tabStop = false;            setWidth(60);            setHeight(80);            setBackColor(SDAConsts.clWhite);            foreColor = SDAConsts.clBlack;            setOnPointerPressed(new PointerEvent() {                public void Event(SDABaseControl ctrl, int x, int y) {                    doPointerPressed(x, y);                }            });        }        //点击        private void doPointerPressed(int x, int y) {            int posx = screenXToClient(x);            int posy = screenYToClient(y);            int fontHeight = getFont().getHeight();            //根据点击的位置判断            if (ImeType == imPinYin) {                if (InClientRect(posx, posy, 0, fontHeight, width, height - 2 * fontHeight)) {                    selectedHanziIndex = (posy - fontHeight) / fontHeight + 4 * (posx / (width / 2));                    getHanziByIndex();                }                //翻页                if (InClientRect(posx, posy, width / 2, height - fontHeight, width / 4, fontHeight)) {                    //左                    priorPage();                }                if (InClientRect(posx, posy, 3 * width / 4, height - fontHeight, width / 4, fontHeight)) {                    //左                    nextpage();                }            }            //字母            if (ImeType == imUpperCase || ImeType == imLowerCase) {                charIndex=posy/fontHeight;                char ch=13;                inputFuncChar(ch);            }        }        //点击选择汉字        protected boolean getHanziByIndex() {            boolean result = false;            if (hanziChars != null) {                if (selectedHanziIndex + (pageNo - 1) * 8 < hanziChars.length && selectedHanziIndex + (pageNo - 1) * 8 > -1) {                    result = true;                    selectedChar = hanziChars[selectedHanziIndex + (pageNo - 1) * 8];                    inputVisibleChar();                    selectedHanziIndex = -1;                    inputChars.setLength(0);                    hanziChars = null;                    isInput = true;                    visible = false;                    form.repaintControl();                }            }            return result;        }        public int getPageScrollBarColor() {            return pageScrollBarColor;        }        public void setPageScrollBarColor(int pageScrollBarColor) {            this.pageScrollBarColor = pageScrollBarColor;        }        public int getPageScrollBarFontColor() {            return pageScrollBarFontColor;        }        public void setPageScrollBarFontColor(int pageScrollBarFontColor) {            this.pageScrollBarFontColor = pageScrollBarFontColor;        }        public int getSelectedBackColor() {            return selectedBackColor;        }        public void setSelectedBackColor(int selectedBackColor) {            this.selectedBackColor = selectedBackColor;        }        public int getSelectedFontColor() {            return selectedFontColor;        }        public void setSelectedFontColor(int selectedFontColor) {            this.selectedFontColor = selectedFontColor;        }        public int getInputBarColor() {            return inputBarColor;        }        public void setInputBarColor(int inputBarColor) {            this.inputBarColor = inputBarColor;        }        //对功能键的处理        protected void inputFuncChar(char inChar) {            //左(输入时移动光标,输入后汉字翻页)            if (inChar == 37) {                if (ImeType == imPinYin) {                    if (isInput && cursorPos > 0) {                        cursorPos--;                    }                    if (!isInput) {                        priorPage();                    }                }                if (ImeType == imUpperCase || ImeType == imLowerCase) {                    if (numChars != null) {                        priorChar();                    }                }            }            //上(对汉字等上下滚动)            if (inChar == 38) {                if (!isInput && ImeType == imPinYin) {                    //翻页                    if (pageNo > 1 && selectedHanziIndex == (pageNo - 1) * 8) {                        priorPage();                        return;                    }                    //选择向上                    if (selectedHanziIndex > 0) {                        selectedHanziIndex--;                    } else {                        isInput = true;                    }                }                if (ImeType == imUpperCase || ImeType == imLowerCase) {                    if (numChars != null) {                        priorChar();                    }                }            }            //右            if (inChar == 39) {                if (ImeType == imPinYin) {                    if (isInput && cursorPos < inputChars.length()) {                        cursorPos++;                    }                    if (!isInput) {                        nextpage();                    }                }                if (ImeType == imUpperCase || ImeType == imLowerCase) {                    if (numChars != null) {                        nextChar();                    }                }            }            //下(滚动选择内容)            if (inChar == 40) {                if (ImeType == imPinYin) {                    if (!isInput) {                        if (pageNo < pageCount && selectedHanziIndex == (pageNo - 1) * 8 + 7) {                            nextpage();                            return;                        }                        if (selectedHanziIndex < hanziCount - 1) {                            selectedHanziIndex++;                        }                    } else {                        if (hanziChars != null) {                            selectedHanziIndex = 0;                            isInput = false;                        }                    }                }                if (ImeType == imLowerCase || ImeType == imUpperCase) {                    if (numChars != null) {                        nextChar();                    }                }            }            //删除            if (inChar == 46) {                if (ImeType == imPinYin) {                    if (cursorPos < inputChars.length()) {                        inputChars.deleteCharAt(cursorPos);                    }                    if (inputChars.length() == 0) {                        visible = false;                    }                }                if (ImeType == imLowerCase || ImeType == imUpperCase) {                    numChars = null;                    visible = false;                }            }            //退格            if (inChar == 8) {                if (ImeType == imPinYin) {                    if (cursorPos > 0 && cursorPos < inputChars.length() + 1) {                        inputChars.deleteCharAt(cursorPos - 1);                        cursorPos--;                    }                    if (inputChars.length() == 0) {                        visible = false;                    }                }                if (ImeType == imLowerCase || ImeType == imUpperCase) {                    numChars = null;                    visible = false;                }            }            //回车            if (inChar == 13) {                if (ImeType == imPinYin) {                    if (isInput) {                        if (hanziChars != null) {                            if (hanziChars.length > 0) {                                isInput = false;                                selectedHanziIndex = 0;                            }                        }                    } else {                        //选择的内容                        if (hanziChars != null) {                            if (selectedHanziIndex > -1 && selectedHanziIndex < hanziCount) {                                selectedChar = hanziChars[selectedHanziIndex];                                inputVisibleChar();                                selectedHanziIndex = -1;                                inputChars.setLength(0);                                hanziChars = null;                                charsPanel.visible = false;

⌨️ 快捷键说明

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