单计算器程序已有,如何用java实现其语音功能()????//前期简单计算器代码如下:
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
public class test_actionevent { /** 
* @param args 
*/ 
public static void main(String[] args) { 
// TODO 自动生成方法存根 
CalculatorFrame frame = new CalculatorFrame(); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置默认的关闭操作 
frame.setVisible(true); } } class CalculatorFrame extends JFrame{//设计了一个容器类,是整个计算器的顶层容器 
public static final int WIDTH = 200; 
public static final int HEIGHT = 200; 
public CalculatorFrame(){ 
this.setTitle("计算器"); 
this.setSize(WIDTH,HEIGHT); 
Container contentPane = this.getContentPane(); 
CalculatorPanel pan = new CalculatorPanel(); 
contentPane.add(pan); 

} class CalculatorPanel extends JPanel{//设计一个计算器的界面,打算用来放置按钮和其他组件 
private JTextField display; 
private JPanel panel; 
private double result; 
private String lastCommand; 
private boolean start; 
public CalculatorPanel(){ 
this.setLayout(new BorderLayout());//设置这个容器的布局格式 
result = 0; 
lastCommand = "="; 
start = true; 
display = new JTextField("0"); 
display.setEditable(true);//设置文本框为不可编辑 this.add(display,BorderLayout.NORTH);//在这个容器里面放置文本框,并将文本框放在北部 ActionListener insert = new InsertAction();//创建了ActionListener对象 
ActionListener command = new CommandAction(); panel = new JPanel();//创建了一个面板对象 
panel.setLayout(new GridLayout(4,4));//将这个panel的布局格式设置为Grid addButton("7",insert);//添加按钮7,并让insert对象的actionPerformed来处理单击操作事件 
addButton("8",insert); 
addButton("9",insert); addButton("/",command);//添加按钮/,并让command对象的actionPerformed来处理单击操作事件 addButton("4",insert); 
addButton("5",insert); 
addButton("6",insert); addButton("*",command); addButton("1",insert); 
addButton("2",insert); 
addButton("3",insert); addButton("-",command); addButton("0",insert); 
addButton(".",insert); 
addButton("=",command); 
addButton("+",command);//添加按钮+,并让command对象的actionPerformed来处理单击操作事件 this.add(panel,BorderLayout.CENTER);//将面板放在中间 
} private void addButton(String label,ActionListener listener){ 
JButton button = new JButton(label);//创建一个按钮,按钮上的字是label 
button.addActionListener(listener);//给创建的按钮注册一个监听器对象 
panel.add(button);//将创建的按钮放到面板上 

private class InsertAction implements ActionListener{ public void actionPerformed(ActionEvent arg0) { 
// TODO 自动生成方法存根 
String input = arg0.getActionCommand(); 
if (start){ 
display.setText(""); 
start = false; 

display.setText(display.getText()+input); 


private class CommandAction implements ActionListener{ public void actionPerformed(ActionEvent arg0) { 
// TODO 自动生成方法存根 
String command = arg0.getActionCommand(); 
if (start){ 
if (command.equals("-")){ 
display.setText(command); 
start = false; 
}else{ 
lastCommand = command; 

}else{ 
calculate(Double.parseDouble(display.getText()));//将文本框中的字符串变成Double,并计算 
lastCommand = command; 
start = true; 



public void calculate(double x){//计算结果 
if (lastCommand.equals("+")) result+=x; 
else if (lastCommand.equals("-")) result-=x; 
else if (lastCommand.equals("*")) result*=x; 
else if (lastCommand.equals("/")) result/=x; 
else if (lastCommand.equals("=")) result=x; display.setText(""+result); } 
} 那个高手可以挑战这个题目:
或者您写一个完整的也可以.先谢了

解决方案 »

  1.   

    先把1020000专成中文  一百零二万,然后找个TTS引擎就成了
      

  2.   

    不过,Java播放音频文件怎么弄呢?JDK安装包只能播放简单的几个音频格式,要播放其它的需要解码器没有做过,请高手前来讲解一下。
      

  3.   

    > 这个题目如果只是简单的读音的拼凑就没什么意思了程序的目的是使复杂的事情简单化,而不是刚好相反> 起码应该实现102500的功能楼上不是有回答吗,你准备一下,把102500解析成“十万二千五百”,然后准备“零一二...十百千万亿兆”这么几个音频文件足矣
      

  4.   

    哦.......
    明白了
    但是现在我java还是比较菜,能有哪位写出一个可运行的代码给下参考?
    不胜感激,能较好实现者定追加50分