java闹钟_JAVA 闹钟程序

这是一个使用Java编写的Applet程序,实现了闹钟功能。通过GregorianCalendar、SimpleDateFormat和AudioClip等类来设置、显示和播放闹钟。用户可以设置闹钟的小时、分钟和秒,当设定时间到达时,程序会播放音频并显示闹钟图像。
摘要由CSDN通过智能技术生成

展开全部

import java.util.*;

import java.awt.*;

import java.applet.*;

import java.text.*;

import java.awt.event.*;

public class Alarm extends Applet implements Runnable

{

Thread timer=null; //创建线程timer

Image gif1; //clockp:闹钟的外壳,闹铃和报时物

boolean setflag=false,stopflag=false,cancelflag=false;

Panel setpanel;

//获取声音文件

AudioClip ring=getAudioClip(getCodeBase(), "1.mid");

Button setbutton=new Button("SET");

Button cancelbutton=new Button("CANCEL");

Button stopbutton=new Button("STOP");

//响应按钮事件

private ActionListener setli=new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

setflag=true;

}

};

private ActionListener cancelli=new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

setflag=true;

}

};

private ActionListener stopli=new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

ring.stop();

//清除的方法

//g.clearRect(83,280,20,30);

}

};

Label note1=new Label("Alarm clock:");

//GregorianCalendar提供的是一32313133353236313431303231363533e59b9ee7ad9431333236396533个日历式的东东,上面又多了很多的参数,是方便操作了不少。而Date类的功能远不及其,求个和日期有联系的还要自己计算。

GregorianCalendar cal=new GregorianCalendar();

GregorianCalendar cal2=new GregorianCalendar();

SimpleDateFormat df=new SimpleDateFormat("yyyy MM dd HH:mm:ss");//设置时间格式

Date dummy=new Date(); //生成Data对象

String lastdate=df.format(dummy);

Font F=new Font("TimesRoman",Font.PLAIN,14);//设置字体格式

Date dat=null;

Date timeNow;

Color fgcol=Color.blue;

Color fgcol2=Color.darkGray;

Color backcolor=Color.blue;

Label hlabel2,mlabel2,slabel2;//显示时间单位时所用的标签(时、分、秒)

int i;

int s,m,h;

Te

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值