ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:17.60KB ,
资源ID:11163165      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11163165.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(用java写的音乐时钟万年历.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

用java写的音乐时钟万年历.docx

1、用java写的音乐时钟万年历import java.awt.*;import java.util.*;import java.awt.image.*;import java.applet.*;/Film是描述滚动图片的类class Film extends Canvas implements RunnableThread move;Image thumb;int startPoint=0;/起始位置final int thumbWidth=23;/小图片的宽度 public Film(Image thumb) this.thumb=thumb; if(move=null) move=new T

2、hread(this); move.start(); public void run() while(true) repaint(); try Thread.sleep(100); catch(InterruptedException e) startPoint-=1;/向左移一位 startPoint%=thumbWidth;/超过小图片宽度后回到起始点 public void paint(Graphics g)update(g);public void update(Graphics g)int i;Dimension d=size();Image offImage=createImage

3、(d.width,d.height);Graphics offG=offImage.getGraphics();offG.setColor(new Color(160,255,160);offG.fillRect(0,0,d.width,d.height);for(i=startPoint;i=d.width;i+=thumbWidth) offG.drawImage(thumb,i,0,this);g.drawImage(offImage,0,0,this);/AudioPlayer是描述底部音乐播放条的类class AudioPlayer extends PanelAudioClip au

4、;Button play,loop,stop;Label label;AudioPlayer(AudioClip au)setLayout(new FlowLayout(FlowLayout.RIGHT,10,5);add(play=new Button(play);add(loop=new Button(loop);add(stop=new Button(stop);this.au=au;setBachground(new Color(160,255,160);public boolean action(Event e,Object p) if(e.target=play) au.play(

5、); else if(e.target=loop) au.loop(); else if(e.target=stop) au.stop(); return super.action(e,p);/Calendar是描述日历和时钟的类class Calendar extends Panel implements Runnable Button nextYear,nextMonth,nextDate,lastYear,lastMonth,lastDate; TextField year,month,date; Film myFilm; Thread clock; AudioClip chirp; D

6、ate today=new Date(); String weekName=Sun,Mon,Tue,Wed,Thu,Fri,Sat; String monthName=一月,二月,三月,四月,五月,六月,七月,八月,九月,十 月,十一月,十二月; int weekColor=0xcc6633,0xcccc33,0xcccc33,0xcccc33,0xcccc33,0xcccc33,0x3399cc; Calendar(Image thumb,AudioClip au) setLayout(new FlowLayout(FlowLayout.LEFT,3,13); add(lastYear=ne

7、w Button(); add(lastMonth=new Button(); add(lastDate=new Button(); myFilm=new Film(thumb); myFilm.resize(270,15); add(myFilm); chirp=au;public void run()long startTime=System.currentTimeMillis();/记录线程开始的时间 while(true) repaint(); startTime+=1000;/计算下次醒来的时间 try Thread.sleep(Math.max(0,startTime-System

8、.currentTimeMillis(); /保证绘图时间和睡眠时间相加为1s,若绘图超过1s,则线程不睡眠 catch(InterruptedException e) public void paint(Graphics g)update(g);public void update(Graphics g)int i,j;Dimension d=size();Image offImage=createImage(d.width,d.height);Graphics offG=offImage.getGraphics();/设置背景色setBackground(new Color(160,255

9、,160);offG.setColor(getBackground();offG.fillRect(0,0,500,350);/画日历背景offG.setColor(new Color(80,150,80);offG.fillRect(25,100,340,230);/draw calendar baseoffG.setColor(new Color(100,230,195);offG.fillRect(15,90,340,230);offG.setFont(new Font(Helvetica,Font.BOLD,20);for(i=0;i0;i-=10)offG.setColor(new

10、Color(170+85*i/350,255,170+85*i/350);offG.fillRect(380,i,40,9);/画年offG.setColor(new Color(200,255,200);offG.setFont(new Font(Courier,Font.ITALIC,66);String yearString=+(1900+today.getYear();for(j=0;j=6;j+=2)for(i=0;i=3;i+) offG.drawString(yearString.substring(i,i+1),415+j,168+49*i);/画水平滚动条offG.setCo

11、lor(Color.black);offG.drawLine(6,60,250,60);offG.setColor(new Color(100,200,100);offG.drawLine(5,65,495,65);offG.drawLine(5,66,495,66);/画圆offG.setColor(Color.yellow);offG.drawOval(360,5,120,120);offG.setColor(Color.orange);offG.drawOval(370,15,100,100);/画月offG.setFont(new Font(Monospaced,Font.BOLD+F

12、ont.ITALIC,25);offG.setColor(Color.orange);offG.drawString(monthNametoday.getMonth(),280,57);/画日期Font myFont=new Font(DialogInput,Font.BOLD,50);FontMetrics fontSize=getFontMetrics(myFont);offG.setFont(myFont);String temp=+today.getDate();Color dateColor=new Color(weekColortoday.getDay();int x=380-fo

13、ntSize.stringWidth(temp)/2;int y=59;offG.setColor(dateColor.brighter();offG.drawString(temp,x-1,y-1);offG.setColor(dateColor.darker();offG.drawString(temp,x+1,y+1);offG.setColor(dateColor);offG.drawString(temp,x,y);/画时钟offG.setColor(Color.yellow);offG.drawOval(360,60,10,10);/9点offG.drawOval(470,60,1

14、0,10);/3点offG.drawOval(415,5,10,10);/12点offG.drawOval(415,115,10,10);/6点offG.drawOval(371,36,5,5);/10点offG.drawOval(391,16,5,5);/11点offG.drawOval(444,16,5,5);/1点offG.drawOval(463,36,5,5);/2点offG.drawOval(363,89,5,5);/4点offG.drawOval(444,109,5,5);/5点offG.drawOval(391,109,5,5);/7点offG.drawOval(371,89,

15、5,5);/8点Date now=new Date();double hour=now.getHours()+now.getMinutes()/60;double minute=now.getMinutes()+now.getSeconds()/60;double second=now.getSeconds();offG.setColor(Color.black);offG.drawLine(420,65,(int)(420+30*Math.sin(hour*Math.PI/6),(int)(65-30*Math.cos(hour*Math.PI/6);offG.drawLine(420,65

16、,(int)(420+45*Math.sin(minute*Math.PI/30),(int)(65-45*Math.cos(minute*Math.PI/30);offG.setColor(Color.pink);offG.drawLine(420,65,(int)(420+48*Math.sin(second*Math.PI/30),(int)(65-48*Math.cos(second*Math.PI/30);/绘日期boolean raised;offG.setFont(new Font(Serif,Font.PLAIN,15);Date newDay=new Date(today.g

17、etYear(),today.getMonth(),1);newDay.setDate(1-newDay.getDay();/找出日历左上角的日期for(j=0;j=5;j+) for(i=0;i16&x113&y=1000&num=1&num=12) today.setMonth(num-1); repaint(); if(evt.target.equals(date) num=Integer.valueOf(date.getText().intValue(); if(num!=today.getDate() Date newDay=new Date(today.getTime(); new

18、Day.setDate(num); if(newDay.getMonth()=today.getMonth() today.setDate(num); repaint(); catch(NumberFormatException e)/输入的不是数字setDateText();输入不合法,将日期设为原值return true;public boolean keyDown(Event evt,int key)if(key=10) return(lostFocus(evt,evt.arg);/按了回车键else return (super.keyDown(evt,key);void setDate

19、Text()year.setText(+(1900+today.getYear();month.setText(+(today.getMonth()+1);date.setText(+today.getDate();public class MyApplet extends AppletCalendar calendar;AudioPlayer audioPlayer;public void init()String auname=getParameter(auname);if(auname=null) auname=ding.au;AudioClip au=getAudioClip(getC

20、odeBase(),auname);audioPlayer=new AudioPlayer(au);Image thumb=getImage(getCodeBase(),thumb.gif);au=getAudioClip(getCodeBase(),chirp.au);calendar=new Calendar(thumb,au);setLayout(new BorderLayout();add(Center,calendar);add(South,audioPlayer);public void start() if(calendar.myFilm.move=null) calendar.

21、myFilm.move=new Thead(calendar.myFilm); calendar.myFilm.move.start(); if(calendar.clock=null) calendar.clock=new Thread(calendar); calendar.clock.start(); public void stop() calendar.myFilm.move.stop(); calendar.myFilm.move=null; calendar.clock.stop(0; calendar.clock=null;public void destroy()audioPlayer.au.stop();super.destroy();

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1