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

📄 unicodelist.java

📁 Unicode list. Can translate between unicode character strings and numbers.
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
/**
 * @author <table width=30%><tr><marquee bgColor=yellow><font color=red>Dai Fei<br>Matriculation Number: u0605169</font></marquee></table>
 */
class UnicodeList {
    
    //public static final Font defaultFont = new Font("Microsoft Arial Unicode", Font.PLAIN, 12);
    public static final Font defaultFont = new Font("Monospaced", Font.PLAIN, 12);
    
    private static final int BUTTONS_PER_PAGE = 256;
    private int pageBuff = 0;
    private JTextField page;
    private JFrame window;
    private Container contentPane;
    private Container codePane;
    private GridBagLayout gridBagLayout;
    private GridBagConstraints gridBagConstraints;
    private Label range;
    
    private int getPage() {
        int p;
        try{
            p = (new Integer(page.getText())).intValue();
        }catch(Exception e){
            return pageBuff;
        }
        pageBuff = p;
        return p;
    }
    
    private void gotoPage(int p) {
        while(p < 0)p += (int) Math.ceil(65536.0 / BUTTONS_PER_PAGE);
        p = p % (int) Math.ceil(65536.0 / BUTTONS_PER_PAGE);//(For Unicode-16 plane 0)
        
        window.setVisible(false);
        contentPane.remove(codePane);
        page.setText("" + p);
        range.setText("" + p * BUTTONS_PER_PAGE + " -- " + ((p + 1) * BUTTONS_PER_PAGE - 1));
        codePane = new Container();
        codePane.setLayout(new GridLayout(16, 1));
        for(int i = 0; i < BUTTONS_PER_PAGE; i++){
            codePane.add(new CodeListButton(p * BUTTONS_PER_PAGE + i, window));
        }
        gridBagLayout.setConstraints(codePane, gridBagConstraints);
        contentPane.setLayout(gridBagLayout);
        contentPane.add(codePane);
        window.pack();
        window.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width  / 2 - window.getSize().width  / 2,
                           Toolkit.getDefaultToolkit().getScreenSize().height / 2 - window.getSize().height / 2);
        window.setVisible(true);
        page.requestFocusInWindow();
    }
    
    private void num2str(JTextField codechar) {
        int num = 0;
        StringBuffer str = new StringBuffer();
        Scanner scanner = new Scanner(codechar.getText());
        while(scanner.hasNextInt()){
            num = scanner.nextInt();
            str.append((char) num);
        }
        if(str.toString().equals("")){
            JOptionPane.showMessageDialog(window, "Cannot convert", "Convert to String", 0);
        }else{
            codechar.setText(str.toString());
            JOptionPane.showMessageDialog(window, str.toString(), "Convert to String", -1);
        }
        gotoPage(num / BUTTONS_PER_PAGE);
    }
    private void str2num(JTextField codechar) {
        if(!codechar.getText().equals("")){
            char c = 0;
            StringBuffer str = new StringBuffer();
            for(int i = 0; i < codechar.getText().length() - 1; i++){
                c = codechar.getText().charAt(i);
                str.append("" + (int) c + " ");
            }
            c = codechar.getText().charAt(codechar.getText().length() - 1);
            str.append("" + (int) c);
            JOptionPane.showMessageDialog(window, str.toString(), "Convert to Digits", -1);
            codechar.setText(str.toString());
            gotoPage(c / BUTTONS_PER_PAGE);
        }
    }
    
    public void start(){
        window = new JFrame("Unicode List (For Unicode-16 plane 0)");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        contentPane = window.getContentPane();
        
        final JTextField codechar = new JTextField("Try it!", 40);
        codechar.setFont(defaultFont);
        JButton toChar = new JButton("65 66 >> AB");
        toChar.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {num2str(codechar);}});
        JButton toCode = new JButton("AB >> 65 66");
        toCode.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {str2num(codechar);}});
        Container searchPane = new Container();
        searchPane.setLayout(new FlowLayout());
        searchPane.add(codechar);
        searchPane.add(toCode);
        searchPane.add(toChar);
        
        Label label = new Label("Page");
        page = new JTextField("0", 4);
        page.setHorizontalAlignment(JTextField.CENTER);
        page.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {gotoPage(getPage()    );}});
        JButton prev = new JButton("Prev");
        prev.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {gotoPage(getPage() - 1);}});
        prev.setMnemonic(KeyEvent.VK_P);
        JButton goTo = new JButton("Goto");
        goTo.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {gotoPage(getPage()    );}});
        goTo.setMnemonic(KeyEvent.VK_G);
        JButton next = new JButton("Next");
        next.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {gotoPage(getPage() + 1);}});
        next.setMnemonic(KeyEvent.VK_N);
        range = new Label();
        Container controlPane = new Container();
        controlPane.setLayout(new FlowLayout());
        controlPane.add(label);
        controlPane.add(page);
        controlPane.add(prev);
        controlPane.add(goTo);
        controlPane.add(next);
        controlPane.add(range);
        
        codePane = new Container();

        gridBagLayout = new GridBagLayout();
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagLayout.setConstraints(searchPane, gridBagConstraints);
        gridBagLayout.setConstraints(controlPane, gridBagConstraints);
        gridBagLayout.setConstraints(codePane, gridBagConstraints);
        contentPane.setLayout(gridBagLayout);
        contentPane.add(searchPane);
        contentPane.add(controlPane);
        
        gotoPage(getPage());
    }
    
    public static void main(String[] args) {
        UnicodeList start = new UnicodeList();
        start.start();
    }
}

class CodeListButton extends JButton implements ActionListener {
    private JFrame window;
    public CodeListButton(final int code, JFrame window) {
        super("" + (char) code);
        this.window = window;
        setFont(UnicodeList.defaultFont);
        addActionListener(this);
    }
    public void actionPerformed(ActionEvent e){
        int code = ((JButton) e.getSource()).getText().charAt(0);
        StringBuffer message = new StringBuffer();
        message.append("0x");
        String hex = Integer.toHexString(code);
        for(int i = 0; i < 6 - hex.length(); i++)message.append("0");
        message.append(hex + "(" + code + "):\n" + (char) code);
        JOptionPane.showMessageDialog(window, message);
    };
}

⌨️ 快捷键说明

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