java

位置:IT落伍者 >> java >> 浏览文章

Java实现把汉字转化成拼音


发布日期:2024年06月04日
 
Java实现把汉字转化成拼音

GUI代码部分

/**

* @(#)CnToSpellGUIjava

* kindani

* ??

* */

import javaawt*;

import javaawtevent*;

import javaxswing*;

import javaxswingevent*;

/**

*

*

JDK版本

* @author KIN

* @version

* @see

* @since

*/

public class CnToSpellGUI extends JFrame {

private CnToSpellGUI c = null;

public CnToSpellGUI () {

super(Cn to Spell);

setSize();

getContentPane()setLayout(new FlowLayout());

// component layout

JTextArea from = new JTextArea();

JTextArea to = new JTextArea();

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

baddActionListener(new CnPinyinActionListener(fromto));

setVisible(true);

// set this for pack

c = this;

}

/**button action listener to convert text to pinyin from one textbox to another textbox*/

class CnPinyinActionListener implements ActionListener{

private JTextArea from = null;

private JTextArea to = null;

public CnPinyinActionListener(JTextArea from JTextArea to) {

thisfrom = from;

thisto = to;

}

public void actionPerformed(ActionEvent e) {

if (fromgetText()length() == ) {

JOptionPaneshowMessageDialog(fromFrom text is empty!WarningJOptionPaneWARNING_MESSAGE);

}

String text = fromgetText();

tosetText(CnToSpellgetFullSpell(text));

cpack();

}

}

public static void main(String [] args) {

CnToSpellGUI g = new CnToSpellGUI();

}

}

/**

* @(#)CnToSpelljava

*               

上一篇:IBM Java如何做到高性能GC的实现内幕

下一篇:Java SE 6 新特性: 对脚本语言的支持