服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

j2se综合--java实现把汉字转化成拼音

gui代码部分:
/**
 * @(#)cntospellgui.java
 * kindani
 * 2004-10-25??
 * */

  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import javax.swing.event.*;

/**
 * 


 * 
jdk版本

1.4

 * @author   kin
 * @version  1.0
 * @see
 * @since   1.0
 */
public class cntospell2gui extends jframe {

 private cntospell2gui c = null;
 
    public cntospell2gui () {
        super("cn to spell");
        setsize(800,100);
        getcontentpane().setlayout(new flowlayout());
        // component layout
        jtextarea from = new jtextarea(5,20);
        jtextarea to = new jtextarea(5,20);
        jbutton b = new jbutton("cn to pinyin");
        getcontentpane().add(new jlabel("from:"));
        getcontentpane().add(from);
        getcontentpane().add(b);
        getcontentpane().add(new jlabel("to:"));
        getcontentpane().add(to);
        // action handle
        b.addactionlistener(new cn2pinyinactionlistener(from,to));
        setvisible(true);
        // set this for pack
        c = this;
    }

    /**button action listener to convert text to pinyin from one textbox to another textbox*/
    class cn2pinyinactionlistener implements actionlistener{

        private jtextarea from = null;
        private jtextarea to = null;
        public cn2pinyinactionlistener(jtextarea from, jtextarea to) {
            this.from = from;
            this.to = to;
        }
        public void actionperformed(actionevent e) {
            if (from.gettext().length() == 0) {
                joptionpane.showmessagedialog(from,"from text is empty!","warning",joptionpane.warning_message);
            }
            string text = from.gettext();
            to.settext(cntospell.getfullspell(text));
            c.pack();
        }
    }

    public static void main(string []  args) {
        cntospell2gui g = new cntospell2gui();
    }
}



------------------------------------------------------------------------
/**
 * @(#)cntospell.java 
 * 版权声明 easydozer 版权所有 违者必究 
 *
 * 修订记录:
 * 1)更改者:easydozer
 *   时 间:2004-10-20 
 *   描 述:创建
 */
package com.easydozer.commons.util;

import java.util.iterator;
import java.util.linkedhashmap;
import java.util.set;

/**
 * 
汉字转化为全拼

 * 
jdk版本:

1.4

 * @author   谢计生
 * @version  1.0
 * @see      
 * @since   1.0
 */
public class cntospell
{
  private static linkedhashmap spellmap = null;

  static
  {
    if(spellmap == null){
      spellmap = new linkedhashma

扫描关注微信公众号