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

📄 amexcardfield.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
字号:
package com.jmobilecore.ui;

/**
 * This class displays text field for entering bank card AmericanExpress
 * card information (format is: 1234 567890 12345)
 *
 * @author Greg Gridin
 */
public class AmexCardField extends BankCardField {

    /**
     * Implementation of abstract <code>BankCardField</code> method
     *
     * @return <code>CustomFieldComposer</code> for AmericanExpress card
     */
    protected CustomFieldComposer initComposer() {
        TextBlockComposer[] textBlocks = new TextBlockComposer[3];
        textBlocks[0] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 4);
        textBlocks[1] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 6);
        textBlocks[2] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 5);

        return new CustomFieldComposer(textBlocks) {
            public void setText(String text) {
                if (text == null || text.length() != getMaxSize()) return;
                textBlocks[0].setText(text.substring(0, 4));
                textBlocks[1].setText(text.substring(4, 10));
                textBlocks[2].setText(text.substring(10, 15));
                setCaretPosition(0);
            }
        };
    }

    protected char[] getFormattedText(boolean calcCursorOffset) {

        TextBlockComposer blocks[] = ((CustomFieldComposer) composer).textBlocks;
        currentLength = 17;
        char[] formattedText = new char[currentLength];
        System.arraycopy(blocks[0].getChars(), 0, formattedText, 0, 4);
        formattedText[4] = ' ';
        System.arraycopy(blocks[1].getChars(), 0, formattedText, 5, 6);
        formattedText[11] = ' ';
        System.arraycopy(blocks[2].getChars(), 0, formattedText, 12, 5);
        if (calcCursorOffset) {
            calculatedCaretPosition = composer.getCaretPosition() + ((CustomFieldComposer)composer).getCurrentBlock();
            calculatedCursorOffset = getCursorOffset(formattedText, calculatedCaretPosition);
        }
        return formattedText;
    }

}

⌨️ 快捷键说明

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