闹钟安卓java源代码 java闹钟小程序( 九 )


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);
//加入一些附加的信息标签(题头闹钟安卓java源代码,题尾)
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);
//初始化指针位置
【闹钟安卓java源代码 java闹钟小程序】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");

推荐阅读