熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

Java實現把漢字轉化成拼音

2022-06-13   來源: JSP教程 

  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
*
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19554.html

    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.