java鈴聲
1. 用java實現手機鈴聲下載
InputStream is = Connector.openInputStream("http://somesite.com/music.mp3");//首先使用Connector打開一個連接或者打開一個流
byte[] buffer = ....
is.read(buffer...)//然後使用普通的read方法讀取位元組流
OutputStream os = new ....//構建本地輸出流
os.wirte(buffer....)//將鈴聲文件寫出本地
如此即實現了下載。上面只是提供了個思路,不是實際代碼。
2. java中怎麼輸出響鈴聲
到設置里,找到關於java的設定,「聲音:開啟」就哦了,摩托手機的在設置裡面的最後幾個,比較雜牌的在java里,諾基亞在設置里
3. 跪求高手幫忙寫一個JAVA手機鬧鍾程序 實現添加鈴聲和設置多鬧鍾
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
public class AlarmClock extends Applet implements Runnable
{
Thread timer=null; //創建線程timer
Image clockp,gif1,gif2,clock6,clock7; //clockp:鬧鍾的外殼,鬧鈴和報時鳥
int s,m,h,hh;
AudioClip ipAu,danger,chirp;
boolean canPaint=true;
boolean flag=false;
boolean strike=true;
int counter=0;
int lasts;
Image offscreen_buf=null;
int i,j,t=0;
int timeout=166;
int lastxs=0,lastys=0,lastxm=0,lastym=0,lastxh=0,lastyh=0;
Date mmy=new Date(); //生成Data對象
GregorianCalendar cal=new GregorianCalendar();
SimpleDateFormat df=new SimpleDateFormat("yyyy MM dd HH:mm:ss");//設置時間格式
String lastdate=df.format(mmy);
Font F=new Font("TimesRoman",Font.PLAIN,14);//設置字體格式
Date dat=null;
Date timeNow=null;
Color fgcol=Color.blue;
Color fgcol2=Color.darkGray;
Panel setpanel;
Color backcolor=Color.pink;
TextField showhour,showmin,showsec,sethour,setmin,setsec;//顯示當前時間文本框和定時文本框
Button onbutton;
Button offbutton;
Label hlabel1,mlabel1,slabel1,hlabel2,mlabel2,slabel2;//顯示時間單位時所用的標簽(時、分、秒)
Label info1=new Label("歡迎使用定時提醒鬧鍾"),info2=new Label("");
Label note1=new Label("當前時間:"),note2=new Label("鬧鍾設置:");
boolean setalerm=false,clickflag=false;//判斷是否響鈴和振動
int fixh=0,fixm=0,fixs=0;//記錄鬧鍾的定時
public void init()//初始化方法
{
Integer gif_number;
int fieldx=50,fieldy1=120,fieldy2=220,fieldw=30,fieldh=20,space=50;//顯示時間和定時文本框的定位參數
setLayout(null); //將布局管理器初始化為null
setpanel=new Panel();
setpanel.setLayout(null);
setpanel.add(note1);
setpanel.add(note2);
note1.setBounds(30,100,60,20);
note1.setBackground(backcolor);
note1.setForeground(Color.black);
note2.setBounds(30,180,60,20);
note2.setBackground(backcolor);
note2.setForeground(Color.black);
hlabel1=new Label();
mlabel1=new Label();
slabel1=new Label();
hlabel2=new Label();
mlabel2=new Label();
slabel2=new Label();
//顯示當前時間用的文本框
showhour=new TextField("00",5);
showmin=new TextField("00",5);
showsec=new TextField("00",5);
//定時用的文本框(時、分、秒)
sethour=new TextField("00",5);
setmin=new TextField("00",5);
setsec=new TextField("00",5);
//當前時間用的文本框的位置、大小
setpanel.add(showhour);
showhour.setBounds(fieldx,fieldy1,fieldw,fieldh);
showhour.setBackground(Color.white);
//在文本框後加入單位「時」
setpanel.add(hlabel1);
hlabel1.setText("時");
hlabel1.setBackground(backcolor);
hlabel1.setForeground(Color.black);
hlabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=fieldx+space;
//當前時間的分鍾文本框的位置、大小
setpanel.add(showmin);
showmin.setBounds(fieldx,fieldy1,fieldw,fieldh);
showmin.setBackground(Color.white);
//在文本框後加入單位「分」
setpanel.add(mlabel1);
mlabel1.setText("分");
mlabel1.setBackground(backcolor);
mlabel1.setForeground(Color.black);
mlabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=fieldx+space;
//當前時間的秒文本框的位置、大小
setpanel.add(showsec);
showsec.setBounds(fieldx,fieldy1,fieldw,fieldh);
showsec.setBackground(Color.white);
//在文本框後加入單位「秒」
setpanel.add(slabel1);
slabel1.setText("秒");
slabel1.setBackground(backcolor);
slabel1.setForeground(Color.black);
slabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=50;
//定時的小時文本框的位置、大小
setpanel.add(sethour);
sethour.setBounds(fieldx,fieldy2,fieldw,fieldh);
sethour.setBackground(Color.white);
//在文本框後加入單位「時」
setpanel.add(hlabel2);
hlabel2.setText("時");
hlabel2.setBackground(backcolor);
hlabel2.setForeground(Color.black);
hlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
fieldx=fieldx+space;
//定時的分鍾文本框的位置、大小
setpanel.add(setmin);
setmin.setBounds(fieldx,fieldy2,fieldw,fieldh);
setmin.setBackground(Color.white);
//在文本框後加入單位「分」
setpanel.add(mlabel2);
mlabel2.setText("分");
mlabel2.setBackground(backcolor);
mlabel2.setForeground(Color.black);
mlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
fieldx=fieldx+space;
//定時的秒文本框的位置、大小
setpanel.add(setsec);
setsec.setBounds(fieldx,fieldy2,fieldw,fieldh);
setsec.setBackground(Color.white);
//在文本框後加入單位「秒」
setpanel.add(slabel2);
slabel2.setText("秒");
slabel2.setBackground(backcolor);
slabel2.setForeground(Color.black);
slabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
//設置鬧鍾控制按鈕(on,off)
onbutton=new Button("開");
offbutton=new Button("關");
setpanel.add(onbutton);
setpanel.add(offbutton);
onbutton.setBounds(90,180,40,20);
offbutton.setBounds(140,180,40,20);
//加入一些附加的信息標簽(題頭,題尾)
setpanel.add(info1);
info1.setBackground(backcolor);
info1.setForeground(Color.blue);
info1.setBounds(50,50,150,20);
setpanel.add(info2);
info2.setBackground(backcolor);
info2.setForeground(Color.blue);
info2.setBounds(150,280,100,20);
//將面板加入當前容器中,並設置面板的大小和背景色
add(setpanel);
setpanel.setBounds(300,1,250,420);
setpanel.setBackground(backcolor);
//獲取聲音文件
ipAu=getAudioClip(getDocumentBase(),"bells/仙劍.mid");
danger=getAudioClip(getDocumentBase(),"bells/0.mid");
chirp=getAudioClip(getDocumentBase(),"bells/3.mid");
int xcenter,ycenter,s,m,h;
xcenter=145;
ycenter=162;
s=(int)cal.get(Calendar.SECOND);
m=(int)cal.get(Calendar.MINUTE);
h=(int)cal.get(Calendar.HOUR_OF_DAY);
//初始化指針位置
lastxs=(int)(Math.cos(s*3.14f/30-3.14f/2)*30+xcenter);
lastys=(int)(Math.sin(s*3.14f/30-3.14f/2)*30+ycenter);
lastxm=(int)(Math.cos(m*3.14f/30-3.14f/2)*25+xcenter);
lastym=(int)(Math.sin(m*3.14f/30-3.14f/2)*25+ycenter);
lastxh=(int)(Math.cos((h*30+m/2)*3.14f/180-3.14f/2)*18+xcenter);
lastyh=(int)(Math.sin((h*30+m/2)*3.14f/180-3.14f/2)*18+ycenter);
lasts=s;
MediaTracker mt=new MediaTracker(this);//創建Tracke對象
clockp=getImage(getDocumentBase(),"休閑.png");
gif1=getImage(getDocumentBase(),"gif1.gif");
gif2=getImage(getDocumentBase(),"gif2.gif");
clock6=getImage(getDocumentBase(),"clock6.gif");
clock7=getImage(getDocumentBase(),"clock7.gif");
mt.addImage(clockp,i++);
mt.addImage(gif1,i++);
mt.addImage(gif2,i++);
mt.addImage(clock6,i++);
mt.addImage(clock7,i++);
try{mt.waitForAll();}catch(InterruptedException e){};//等待載入結束
resize(600,420);//設置窗口大小
}
public void paint(Graphics g){//重寫paint()方法
int xh,yh,xm,ym,xs,ys,strike_times;
int xcenter,ycenter;
String today;
Integer gif_number;
xcenter=148;
ycenter=186;
dat=new Date();
cal.setTime(dat);
//讀取當前時間
s=(int)cal.get(Calendar.SECOND);
m=(int)cal.get(Calendar.MINUTE);
h=(int)cal.get(Calendar.HOUR_OF_DAY);
today=df.format(dat);
//指針位置
xs=(int)(Math.cos(s*3.14f/30-3.14f/2)*30+xcenter);
ys=(int)(Math.sin(s*3.14f/30-3.14f/2)*30+ycenter);
xm=(int)(Math.cos(m*3.14f/30-3.14f/2)*25+xcenter);
ym=(int)(Math.sin(m*3.14f/30-3.14f/2)*25+ycenter);
xh=(int)(Math.cos((h*30+m/2)*3.14f/180-3.14f/2)*18+xcenter);
yh=(int)(Math.sin((h*30+m/2)*3.14f/180-3.14f/2)*18+ycenter);
//設置字體和顏色
g.setFont(F);
g.setColor(fgcol);
g.setColor(fgcol2);
g.setColor(getBackground());
g.fillRect(1,1,634,419);
g.drawImage(clockp,75,110,this);
g.drawImage(clock6,83,280,this);
g.setColor(fgcol2);
g.setColor(getBackground());
g.setColor(fgcol2);
//以數字方式顯示年、月、日和時間
g.drawString(today,55,415);
g.drawLine(xcenter,ycenter,xs,ys);
g.setColor(fgcol);
//畫指針
g.drawLine(xcenter,ycenter-1,xm,ym);
g.drawLine(xcenter-1,ycenter,xm,ym);
g.drawLine(xcenter,ycenter-1,xh,yh);
g.drawLine(xcenter-1,ycenter,xh,yh);
lastxs=xs;lastys=ys;
lastxm=xh;lastym=ym;
lastxh=xh;lastyh=yh;
lastdate=today;
if(h<12)hh=h;//將系統時間變換到0-11區間
else hh=h-12;
if(hh==0) strike_times=12;//計算整點時鍾聲數
else strike_times=hh;
if((s==0&&m==0)||flag){//判斷是否整點,是否是主動刷新
if(counter<strike_times){
flag=true;
g.drawImage(gif2,115,35,this);
if(lasts!=s){
if(strike){
counter++;
danger.play();//播放鬧鈴聲
}
if(strike)strike=false;
else strike=true;
}
}
else {
counter=0;
flag=false;
}
}
else
g.drawImage(gif1,115,35,this);
int timedelta;//記錄當前時間與鬧鈴定時的時差
Integer currh,currm,currs;//分別記錄當前的時、分、秒
timeNow=new Date();
currh=new Integer(timeNow.getHours());
currm=new Integer(timeNow.getMinutes());
currs=new Integer(timeNow.getSeconds());
//判斷是否要更新當前顯示的時間,這樣可以避免文本框出現頻率閃動
if(currh.intValue()!=Integer.valueOf(showhour.getText()).intValue())
showhour.setText(currh.toString());
if(currm.intValue()!=Integer.valueOf(showmin.getText()).intValue())
showmin.setText(currh.toString());
if(currs.intValue()!=Integer.valueOf(showsec.getText()).intValue())
showsec.setText(currh.toString());
if(setalerm){ //判斷是否設置了鬧鍾
//判斷當前時間是否為鬧鍾所定的時間
if((currh.intValue()==fixh)&&(currm.intValue()==fixm)&&(currs.intValue()==fixs))
clickflag=true;
timedelta=currm.intValue()*60+currs.intValue()-fixm*60-fixs;
if((timedelta<60)&&(clickflag==true)){ //若當前時間與鬧鍾相差時間達到60秒
chirp.play();
g.drawImage(clock7,83,280,this);
}
else{
chirp.stop();
clickflag=false;
}
}
if(lasts!=s)
ipAu.play();//播放滴答聲
lasts=s;
if(canPaint){
t+=1;
if(t==12)t=0;
}
canPaint=false;
dat=null;
}
public void start(){
if(timer==null){
timer=new Thread(this);//將timer實例化
timer.start();
}
}
public void stop(){
timer=null;
}
public void run(){
while(timer!=null){
try{timer.sleep(timeout);}catch(InterruptedException e){}
canPaint=true;
repaint();//刷新畫面
}
timer=null;
}
public void update(Graphics g){ //採用雙緩沖技術的update()方法
if(offscreen_buf==null)
offscreen_buf=createImage(600,420);
Graphics offg=offscreen_buf.getGraphics();
offg.clipRect(1,1,599,419);
paint(offg);
Graphics ong=getGraphics();
ong.clipRect(1,1,599,419);
ong.drawImage(offscreen_buf,0,0,this);
}
public boolean action(Event evt,Object arg){ //按鈕事件處理函數
if(evt.target instanceof Button){
String lable=(String)arg;
if(lable.equals("開")){
setalerm=true;
//獲取輸入的時間
fixh=Integer.valueOf(sethour.getText()).intValue();
fixm=Integer.valueOf(setmin.getText()).intValue();
fixs=Integer.valueOf(setsec.getText()).intValue();
clickflag=false;
}
if(lable.equals("關")){
setalerm=false;
if(chirp!=null)
chirp.stop();
clickflag=false;
}
return true;
}
return false;
}
}
4. 哪裡有Java鈴聲剪輯軟體
搜索鈴聲快剪,電腦端,手機端的軟體都有去三五手機電影論壇看看吧,有不同格式的電影、手機軟體、手機鈴聲、手機游戲、手機游戲、手機電子、手機主題書免費下 http://www.555sj.com/bbs/?a=philchen9898
希望採納
5. 我的手機沒有簡訊鈴聲取代功能(就是像來電鈴聲那樣,取代為記憶卡里的MP3),可以用JAVA程序實現嗎
LZ手機是什麼型號的啊?
在設置-鈴聲設置裡面都會有短消息鈴音改變功能。
鈴聲和JAVA貌似沒有什麼關系吧
6. java怎麼判斷一首鈴音是否單聲道
根本不用
JAVA~~~~~你只需要把鈴聲開起~~然後調音響~~~先關一邊~~再關另外一邊~~~反正就是一次只看一邊~~然後看是否2邊單獨開時都有聲音~~如果有一邊沒聲音的話~~那麼就是單聲道
7. 你好!為什麼我手機是BBKi518在使用java過程中沒有聲音java 手機QQ沒有提示音,java 游戲沒有鈴聲...
你好,先看看手機java設置,裡面有聲音和震動等選項,將java背景音調為開啟,如果還是沒有聲音,那可能是java游戲選項里的聲音關閉了,只要調為開啟就好了
8. java如何設置iPhone鈴聲
下載個IPONE鈴聲,就可以了
9. 請用JAVA編一個鬧鍾程序,符合要求追加100分!急!!
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
public class AlarmClock extends Applet implements Runnable
{
Thread timer=null; //創建線程timer
Image clockp,gif1,gif2,clock6,clock7; //clockp:鬧鍾的外殼,鬧鈴和報時鳥
int s,m,h,hh;
AudioClip ipAu,danger,chirp;
boolean canPaint=true;
boolean flag=false;
boolean strike=true;
int counter=0;
int lasts;
Image offscreen_buf=null;
int i,j,t=0;
int timeout=166;
int lastxs=0,lastys=0,lastxm=0,lastym=0,lastxh=0,lastyh=0;
Date mmy=new Date(); //生成Data對象
GregorianCalendar cal=new GregorianCalendar();
SimpleDateFormat df=new SimpleDateFormat("yyyy MM dd HH:mm:ss");//設置時間格式
String lastdate=df.format(mmy);
Font F=new Font("TimesRoman",Font.PLAIN,14);//設置字體格式
Date dat=null;
Date timeNow=null;
Color fgcol=Color.blue;
Color fgcol2=Color.darkGray;
Panel setpanel;
Color backcolor=Color.pink;
TextField showhour,showmin,showsec,sethour,setmin,setsec;//顯示當前時間文本框和定時文本框
Button onbutton;
Button offbutton;
Label hlabel1,mlabel1,slabel1,hlabel2,mlabel2,slabel2;//顯示時間單位時所用的標簽(時、分、秒)
Label info1=new Label("歡迎使用定時提醒鬧鍾"),info2=new Label("");
Label note1=new Label("當前時間:"),note2=new Label("鬧鍾設置:");
boolean setalerm=false,clickflag=false;//判斷是否響鈴和振動
int fixh=0,fixm=0,fixs=0;//記錄鬧鍾的定時
public void init()//初始化方法
{
Integer gif_number;
int fieldx=50,fieldy1=120,fieldy2=220,fieldw=30,fieldh=20,space=50;//顯示時間和定時文本框的定位參數
setLayout(null); //將布局管理器初始化為null
setpanel=new Panel();
setpanel.setLayout(null);
setpanel.add(note1);
setpanel.add(note2);
note1.setBounds(30,100,60,20);
note1.setBackground(backcolor);
note1.setForeground(Color.black);
note2.setBounds(30,180,60,20);
note2.setBackground(backcolor);
note2.setForeground(Color.black);
hlabel1=new Label();
mlabel1=new Label();
slabel1=new Label();
hlabel2=new Label();
mlabel2=new Label();
slabel2=new Label();
//顯示當前時間用的文本框
showhour=new TextField("00",5);
showmin=new TextField("00",5);
showsec=new TextField("00",5);
//定時用的文本框(時、分、秒)
sethour=new TextField("00",5);
setmin=new TextField("00",5);
setsec=new TextField("00",5);
//當前時間用的文本框的位置、大小
setpanel.add(showhour);
showhour.setBounds(fieldx,fieldy1,fieldw,fieldh);
showhour.setBackground(Color.white);
//在文本框後加入單位「時」
setpanel.add(hlabel1);
hlabel1.setText("時");
hlabel1.setBackground(backcolor);
hlabel1.setForeground(Color.black);
hlabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=fieldx+space;
//當前時間的分鍾文本框的位置、大小
setpanel.add(showmin);
showmin.setBounds(fieldx,fieldy1,fieldw,fieldh);
showmin.setBackground(Color.white);
//在文本框後加入單位「分」
setpanel.add(mlabel1);
mlabel1.setText("分");
mlabel1.setBackground(backcolor);
mlabel1.setForeground(Color.black);
mlabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=fieldx+space;
//當前時間的秒文本框的位置、大小
setpanel.add(showsec);
showsec.setBounds(fieldx,fieldy1,fieldw,fieldh);
showsec.setBackground(Color.white);
//在文本框後加入單位「秒」
setpanel.add(slabel1);
slabel1.setText("秒");
slabel1.setBackground(backcolor);
slabel1.setForeground(Color.black);
slabel1.setBounds(fieldx+fieldw+3,fieldy1,14,20);
fieldx=50;
//定時的小時文本框的位置、大小
setpanel.add(sethour);
sethour.setBounds(fieldx,fieldy2,fieldw,fieldh);
sethour.setBackground(Color.white);
//在文本框後加入單位「時」
setpanel.add(hlabel2);
hlabel2.setText("時");
hlabel2.setBackground(backcolor);
hlabel2.setForeground(Color.black);
hlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
fieldx=fieldx+space;
//定時的分鍾文本框的位置、大小
setpanel.add(setmin);
setmin.setBounds(fieldx,fieldy2,fieldw,fieldh);
setmin.setBackground(Color.white);
//在文本框後加入單位「分」
setpanel.add(mlabel2);
mlabel2.setText("分");
mlabel2.setBackground(backcolor);
mlabel2.setForeground(Color.black);
mlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
fieldx=fieldx+space;
//定時的秒文本框的位置、大小
setpanel.add(setsec);
setsec.setBounds(fieldx,fieldy2,fieldw,fieldh);
setsec.setBackground(Color.white);
//在文本框後加入單位「秒」
setpanel.add(slabel2);
slabel2.setText("秒");
slabel2.setBackground(backcolor);
slabel2.setForeground(Color.black);
slabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20);
//設置鬧鍾控制按鈕(on,off)
onbutton=new Button("開");
offbutton=new Button("關");
setpanel.add(onbutton);
setpanel.add(offbutton);
onbutton.setBounds(90,180,40,20);
offbutton.setBounds(140,180,40,20);
//加入一些附加的信息標簽(題頭,題尾)
setpanel.add(info1);
info1.setBackground(backcolor);
info1.setForeground(Color.blue);
info1.setBounds(50,50,150,20);
setpanel.add(info2);
info2.setBackground(backcolor);
info2.setForeground(Color.blue);
info2.setBounds(150,280,100,20);
//將面板加入當前容器中,並設置面板的大小和背景色
add(setpanel);
setpanel.setBounds(300,1,250,420);
setpanel.setBackground(backcolor);
//獲取聲音文件
ipAu=getAudioClip(getDocumentBase(),"bells/仙劍.mid");
danger=getAudioClip(getDocumentBase(),"bells/0.mid");
chirp=getAudioClip(getDocumentBase(),"bells/3.mid");
int xcenter,ycenter,s,m,h;
xcenter=145;
ycenter=162;
s=(int)cal.get(Calendar.SECOND);
m=(int)cal.get(Calendar.MINUTE);
h=(int)cal.get(Calendar.HOUR_OF_DAY);
//初始化指針位置
lastxs=(int)(Math.cos(s*3.14f/30-3.14f/2)*30+xcenter);
lastys=(int)(Math.sin(s*3.14f/30-3.14f/2)*30+ycenter);
lastxm=(int)(Math.cos(m*3.14f/30-3.14f/2)*25+xcenter);
lastym=(int)(Math.sin(m*3.14f/30-3.14f/2)*25+ycenter);
lastxh=(int)(Math.cos((h*30+m/2)*3.14f/180-3.14f/2)*18+xcenter);
lastyh=(int)(Math.sin((h*30+m/2)*3.14f/180-3.14f/2)*18+ycenter);
lasts=s;
MediaTracker mt=new MediaTracker(this);//創建Tracke對象
clockp=getImage(getDocumentBase(),"休閑.png");
gif1=getImage(getDocumentBase(),"gif1.gif");
gif2=getImage(getDocumentBase(),"gif2.gif");
clock6=getImage(getDocumentBase(),"clock6.gif");
clock7=getImage(getDocumentBase(),"clock7.gif");
mt.addImage(clockp,i++);
mt.addImage(gif1,i++);
mt.addImage(gif2,i++);
mt.addImage(clock6,i++);
mt.addImage(clock7,i++);
try{mt.waitForAll();}catch(InterruptedException e){};//等待載入結束
resize(600,420);//設置窗口大小
}
public void paint(Graphics g){//重寫paint()方法
int xh,yh,xm,ym,xs,ys,strike_times;
int xcenter,ycenter;
String today;
Integer gif_number;
xcenter=148;
ycenter=186;
dat=new Date();
cal.setTime(dat);
//讀取當前時間
s=(int)cal.get(Calendar.SECOND);
m=(int)cal.get(Calendar.MINUTE);
h=(int)cal.get(Calendar.HOUR_OF_DAY);
today=df.format(dat);
//指針位置
xs=(int)(Math.cos(s*3.14f/30-3.14f/2)*30+xcenter);
ys=(int)(Math.sin(s*3.14f/30-3.14f/2)*30+ycenter);
xm=(int)(Math.cos(m*3.14f/30-3.14f/2)*25+xcenter);
ym=(int)(Math.sin(m*3.14f/30-3.14f/2)*25+ycenter);
xh=(int)(Math.cos((h*30+m/2)*3.14f/180-3.14f/2)*18+xcenter);
yh=(int)(Math.sin((h*30+m/2)*3.14f/180-3.14f/2)*18+ycenter);
//設置字體和顏色
g.setFont(F);
g.setColor(fgcol);
g.setColor(fgcol2);
g.setColor(getBackground());
g.fillRect(1,1,634,419);
g.drawImage(clockp,75,110,this);
g.drawImage(clock6,83,280,this);
g.setColor(fgcol2);
g.setColor(getBackground());
g.setColor(fgcol2);
//以數字方式顯示年、月、日和時間
g.drawString(today,55,415);
g.drawLine(xcenter,ycenter,xs,ys);
g.setColor(fgcol);
//畫指針
g.drawLine(xcenter,ycenter-1,xm,ym);
g.drawLine(xcenter-1,ycenter,xm,ym);
g.drawLine(xcenter,ycenter-1,xh,yh);
g.drawLine(xcenter-1,ycenter,xh,yh);
lastxs=xs;lastys=ys;
lastxm=xh;lastym=ym;
lastxh=xh;lastyh=yh;
lastdate=today;
if(h<12)hh=h;//將系統時間變換到0-11區間
else hh=h-12;
if(hh==0) strike_times=12;//計算整點時鍾聲數
else strike_times=hh;
if((s==0&&m==0)||flag){//判斷是否整點,是否是主動刷新
if(counter<strike_times){
flag=true;
g.drawImage(gif2,115,35,this);
if(lasts!=s){
if(strike){
counter++;
danger.play();//播放鬧鈴聲
}
if(strike)strike=false;
else strike=true;
}
}
else {
counter=0;
flag=false;
}
}
else
g.drawImage(gif1,115,35,this);
int timedelta;//記錄當前時間與鬧鈴定時的時差
Integer currh,currm,currs;//分別記錄當前的時、分、秒
timeNow=new Date();
currh=new Integer(timeNow.getHours());
currm=new Integer(timeNow.getMinutes());
currs=new Integer(timeNow.getSeconds());
//判斷是否要更新當前顯示的時間,這樣可以避免文本框出現頻率閃動
if(currh.intValue()!=Integer.valueOf(showhour.getText()).intValue())
showhour.setText(currh.toString());
if(currm.intValue()!=Integer.valueOf(showmin.getText()).intValue())
showmin.setText(currh.toString());
if(currs.intValue()!=Integer.valueOf(showsec.getText()).intValue())
showsec.setText(currh.toString());
if(setalerm){ //判斷是否設置了鬧鍾
//判斷當前時間是否為鬧鍾所定的時間
if((currh.intValue()==fixh)&&(currm.intValue()==fixm)&&(currs.intValue()==fixs))
clickflag=true;
timedelta=currm.intValue()*60+currs.intValue()-fixm*60-fixs;
if((timedelta<60)&&(clickflag==true)){ //若當前時間與鬧鍾相差時間達到60秒
chirp.play();
g.drawImage(clock7,83,280,this);
}
else{
chirp.stop();
clickflag=false;
}
}
if(lasts!=s)
ipAu.play();//播放滴答聲
lasts=s;
if(canPaint){
t+=1;
if(t==12)t=0;
}
canPaint=false;
dat=null;
}
public void start(){
if(timer==null){
timer=new Thread(this);//將timer實例化
timer.start();
}
}
public void stop(){
timer=null;
}
public void run(){
while(timer!=null){
try{timer.sleep(timeout);}catch(InterruptedException e){}
canPaint=true;
repaint();//刷新畫面
}
timer=null;
}
public void update(Graphics g){ //採用雙緩沖技術的update()方法
if(offscreen_buf==null)
offscreen_buf=createImage(600,420);
Graphics offg=offscreen_buf.getGraphics();
offg.clipRect(1,1,599,419);
paint(offg);
Graphics ong=getGraphics();
ong.clipRect(1,1,599,419);
ong.drawImage(offscreen_buf,0,0,this);
}
public boolean action(Event evt,Object arg){ //按鈕事件處理函數
if(evt.target instanceof Button){
String lable=(String)arg;
if(lable.equals("開")){
setalerm=true;
//獲取輸入的時間
fixh=Integer.valueOf(sethour.getText()).intValue();
fixm=Integer.valueOf(setmin.getText()).intValue();
fixs=Integer.valueOf(setsec.getText()).intValue();
clickflag=false;
}
if(lable.equals("關")){
setalerm=false;
if(chirp!=null)
chirp.stop();
clickflag=false;
}
return true;
}
return false;
}
}