我是用eclipse弄得,这音频放在那都不好使!求助大神,顺便问一下给Jbutton加图片也不成功!也是路径问题!
import java.io.File;
import java.util.Calendar;
import java.util.Date;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class Alarm {
public static void main(String args[]){
long time;
String video=null;
String msg=null;
try{
//设置
String strtime=JOptionPane.showInputDialog("输入时间:hh:mm");
String t[]=strtime.split(":");
int hh=Integer.parseInt(t[0]);
int mm=Integer.parseInt(t[1]);
video="c:/User/MXF/Desktop/b.mp3";//JOptionPane.showInputDialog("输入音频路径:(为空则不需要音频)");
if(!new File(video).exists())
video=null;
msg=JOptionPane.showInputDialog("闹钟提示信息:");
//计算
hh-=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
mm-=Calendar.getInstance().get(Calendar.MINUTE);
if(mm<0){
mm+=60;
hh--;
}
if(hh<0){
hh+=24;
}
time=((hh*60+mm)*60-Calendar.getInstance().get(Calendar.SECOND))*1000;
//等待
Thread.sleep(time);
//执行
if(video!=null){
try{
Runtime.getRuntime().exec("start "+video);
}catch(Exception e){
msg+="\n音频文件加载失败!";
}
}
JOptionPane.showMessageDialog(new JFrame(), strtime+"\n"+msg);
}catch(Exception e){
JOptionPane.showMessageDialog(new JFrame(),"闹钟任务失败,原因未明!");
}
}
}
import java.io.File;
import java.util.Calendar;
import java.util.Date;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class Alarm {
public static void main(String args[]){
long time;
String video=null;
String msg=null;
try{
//设置
String strtime=JOptionPane.showInputDialog("输入时间:hh:mm");
String t[]=strtime.split(":");
int hh=Integer.parseInt(t[0]);
int mm=Integer.parseInt(t[1]);
video="c:/User/MXF/Desktop/b.mp3";//JOptionPane.showInputDialog("输入音频路径:(为空则不需要音频)");
if(!new File(video).exists())
video=null;
msg=JOptionPane.showInputDialog("闹钟提示信息:");
//计算
hh-=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
mm-=Calendar.getInstance().get(Calendar.MINUTE);
if(mm<0){
mm+=60;
hh--;
}
if(hh<0){
hh+=24;
}
time=((hh*60+mm)*60-Calendar.getInstance().get(Calendar.SECOND))*1000;
//等待
Thread.sleep(time);
//执行
if(video!=null){
try{
Runtime.getRuntime().exec("start "+video);
}catch(Exception e){
msg+="\n音频文件加载失败!";
}
}
JOptionPane.showMessageDialog(new JFrame(), strtime+"\n"+msg);
}catch(Exception e){
JOptionPane.showMessageDialog(new JFrame(),"闹钟任务失败,原因未明!");
}
}
}
解决方案 »
- java怎样实现qq表情
- 数据结构,离散数学什么的重要吗。。。。。
- 关于一个Timer的问题,这东东怎么只会打印一次,服务器并没有停
- JCreator中如何在builder中使得complile后,文件生成.class文件?
- 求教这个ArrayList所占的内存的大小!
- 请指教:如何使用JFreeChart实现动态曲线?
- 谁知道????????
- 如何让一个窗口不活动时也显示在活动窗口的前面??像windows任务管理器一样
- 我安装了jdk1.3后,怎么没有:。。。。。。
- Java字节输出流,输出byte类型数据乱码是什么原因?
- 多个线程能监听一个端口吗?
- 求正则,包含ab,但不包含abc的表达式,谢谢
{
String result="";
String url=Class.forName("Alarm类的包名.Alarm/*(按你上面写的Alarm类)*/").getResource("/").getPath();
String urls=url.replace("WebRoot/WEB-INF/classes/", url);
result=urls.substring(1,urls.length());
return result;
}//这个方法就是返回你的音频模块的目录,不可能音频、图片不跟不放在项目文件夹里。