Java 关于声音进程的问题
我想利用这段代码实现当鼠标移动到组件内时,提示“您已进入应用”,移动到组件外时提示“您已离开应用”,可结果在鼠标移出组件时没有反应,若注释掉结束进程那段代码,虽然有提示“...
我想利用这段代码实现当鼠标移动到组件内时,提示“您已进入应用”,移动到组件外时提示“您已离开应用”,可结果在鼠标移出组件时没有反应,若注释掉结束进程那段代码,虽然有提示“您已离开应用”,“您已离开应用”提示却不能马上停止,造成了“二重唱”的感觉,改怎样解决?
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
File vbs = new File("E:\\我的程序\\MyJava\\TestDemo\\temp", "ld.vbs");
try
{
String str = null;
String s = "您已进入应用";
fileWriter = new FileWriter(vbs);
out = new BufferedWriter(fileWriter);
str = "CreateObject(\"SAPI.SpVoice\").Speak\"" + s + "\"";
byte[] c = str.getBytes("GB2312");
str = new String(c);
out.write(str);
out.close();
fileWriter.close();
} catch (IOException ee) {
}
try {
Runtime.getRuntime().exec("wscript E:\\我的程序\\MyJava\\TestDemo\\temp\\ld.vbs");
} catch (IOException ee) {
}
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
try //若不注释这几行,程序不能提示“您一离开
{ //应用”;
Runtime.getRuntime().exec("taskkill /f /im wscript.exe"); //若注释掉这几行,能够提示“您已离开应用”
} catch (IOException ee) { //但是“您已进入应用”却不能
} //马上停止,造成“二重唱”的感觉
File vbs = new File("E:\\我的程序\\MyJava\\TestDemo\\temp", "ld.vbs");
try
{
String str = null;
String s = "您已离开应用";
fileWriter = new FileWriter(vbs);
out = new BufferedWriter(fileWriter);
str = "CreateObject(\"SAPI.SpVoice\").Speak\"" + s + "\"";
byte[] c = str.getBytes("GB2312");
str = new String(c);
out.write(str);
out.close();
fileWriter.close();
} catch (IOException ee) {
}
try {
Runtime.getRuntime().exec("wscript E:\\我的程序\\MyJava\\TestDemo\\temp\\ld.vbs");
} catch (IOException ee) {
}
} 展开
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
File vbs = new File("E:\\我的程序\\MyJava\\TestDemo\\temp", "ld.vbs");
try
{
String str = null;
String s = "您已进入应用";
fileWriter = new FileWriter(vbs);
out = new BufferedWriter(fileWriter);
str = "CreateObject(\"SAPI.SpVoice\").Speak\"" + s + "\"";
byte[] c = str.getBytes("GB2312");
str = new String(c);
out.write(str);
out.close();
fileWriter.close();
} catch (IOException ee) {
}
try {
Runtime.getRuntime().exec("wscript E:\\我的程序\\MyJava\\TestDemo\\temp\\ld.vbs");
} catch (IOException ee) {
}
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
try //若不注释这几行,程序不能提示“您一离开
{ //应用”;
Runtime.getRuntime().exec("taskkill /f /im wscript.exe"); //若注释掉这几行,能够提示“您已离开应用”
} catch (IOException ee) { //但是“您已进入应用”却不能
} //马上停止,造成“二重唱”的感觉
File vbs = new File("E:\\我的程序\\MyJava\\TestDemo\\temp", "ld.vbs");
try
{
String str = null;
String s = "您已离开应用";
fileWriter = new FileWriter(vbs);
out = new BufferedWriter(fileWriter);
str = "CreateObject(\"SAPI.SpVoice\").Speak\"" + s + "\"";
byte[] c = str.getBytes("GB2312");
str = new String(c);
out.write(str);
out.close();
fileWriter.close();
} catch (IOException ee) {
}
try {
Runtime.getRuntime().exec("wscript E:\\我的程序\\MyJava\\TestDemo\\temp\\ld.vbs");
} catch (IOException ee) {
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询