在线等——我做的网站需要一个漂亮的钟表......

在线等——我做的网站需要一个漂亮的钟表......,第1张

可以用一个javaApplet

我这正好有个闹钟的代码

import javautil;

import javaawt;

import javaapplet;

import javatext;

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 dummy=new Date(); //生成Data对象

GregorianCalendar cal=new GregorianCalendar();

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

String lastdate=dfformat(dummy);

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

Date dat=null;

Date timeNow=null;

Color fgcol=Colorblue;

Color fgcol2=ColordarkGray;

Panel setpanel;

Color backcolor=Colorpink;

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();

setpanelsetLayout(null);

setpaneladd(note1);

setpaneladd(note2);

note1setBounds(30,100,60,20);

note1setBackground(backcolor);

note1setForeground(Colorblack);

note2setBounds(30,180,60,20);

note2setBackground(backcolor);

note2setForeground(Colorblack);

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);

//当前时间用的文本框的位置、大小

setpaneladd(showhour);

showhoursetBounds(fieldx,fieldy1,fieldw,fieldh);

showhoursetBackground(Colorwhite);

//在文本框后加入单位“时”

setpaneladd(hlabel1);

hlabel1setText("时");

hlabel1setBackground(backcolor);

hlabel1setForeground(Colorblack);

hlabel1setBounds(fieldx+fieldw+3,fieldy1,14,20);

fieldx=fieldx+space;

//当前时间的分钟文本框的位置、大小

setpaneladd(showmin);

showminsetBounds(fieldx,fieldy1,fieldw,fieldh);

showminsetBackground(Colorwhite);

//在文本框后加入单位“分”

setpaneladd(mlabel1);

mlabel1setText("分");

mlabel1setBackground(backcolor);

mlabel1setForeground(Colorblack);

mlabel1setBounds(fieldx+fieldw+3,fieldy1,14,20);

fieldx=fieldx+space;

//当前时间的秒文本框的位置、大小

setpaneladd(showsec);

showsecsetBounds(fieldx,fieldy1,fieldw,fieldh);

showsecsetBackground(Colorwhite);

//在文本框后加入单位“秒”

setpaneladd(slabel1);

slabel1setText("秒");

slabel1setBackground(backcolor);

slabel1setForeground(Colorblack);

slabel1setBounds(fieldx+fieldw+3,fieldy1,14,20);

fieldx=50;

//定时的小时文本框的位置、大小

setpaneladd(sethour);

sethoursetBounds(fieldx,fieldy2,fieldw,fieldh);

sethoursetBackground(Colorwhite);

//在文本框后加入单位“时”

setpaneladd(hlabel2);

hlabel2setText("时");

hlabel2setBackground(backcolor);

hlabel2setForeground(Colorblack);

hlabel2setBounds(fieldx+fieldw+3,fieldy2,14,20);

fieldx=fieldx+space;

//定时的分钟文本框的位置、大小

setpaneladd(setmin);

setminsetBounds(fieldx,fieldy2,fieldw,fieldh);

setminsetBackground(Colorwhite);

//在文本框后加入单位“分”

setpaneladd(mlabel2);

mlabel2setText("分");

mlabel2setBackground(backcolor);

mlabel2setForeground(Colorblack);

mlabel2setBounds(fieldx+fieldw+3,fieldy2,14,20);

fieldx=fieldx+space;

//定时的秒文本框的位置、大小

setpaneladd(setsec);

setsecsetBounds(fieldx,fieldy2,fieldw,fieldh);

setsecsetBackground(Colorwhite);

//在文本框后加入单位“秒”

setpaneladd(slabel2);

slabel2setText("秒");

slabel2setBackground(backcolor);

slabel2setForeground(Colorblack);

slabel2setBounds(fieldx+fieldw+3,fieldy2,14,20);

//设置闹钟控制按钮(on,off)

onbutton=new Button("开");

offbutton=new Button("关");

setpaneladd(onbutton);

setpaneladd(offbutton);

onbuttonsetBounds(90,180,40,20);

offbuttonsetBounds(140,180,40,20);

//加入一些附加的信息标签(题头,题尾)

setpaneladd(info1);

info1setBackground(backcolor);

info1setForeground(Colorblue);

info1setBounds(50,50,150,20);

setpaneladd(info2);

info2setBackground(backcolor);

info2setForeground(Colorblue);

info2setBounds(150,280,100,20);

//将面板加入当前容器中,并设置面板的大小和背景色

add(setpanel);

setpanelsetBounds(300,1,250,420);

setpanelsetBackground(backcolor);

//获取声音文件

ipAu=getAudioClip(getDocumentBase(),"bells/仙剑mid");

danger=getAudioClip(getDocumentBase(),"bells/0mid");

chirp=getAudioClip(getDocumentBase(),"bells/3mid");

int xcenter,ycenter,s,m,h;

xcenter=145;

ycenter=162;

s=(int)calget(CalendarSECOND);

m=(int)calget(CalendarMINUTE);

h=(int)calget(CalendarHOUR_OF_DAY);

//初始化指针位置

lastxs=(int)(Mathcos(s314f/30-314f/2)30+xcenter);

lastys=(int)(Mathsin(s314f/30-314f/2)30+ycenter);

lastxm=(int)(Mathcos(m314f/30-314f/2)25+xcenter);

lastym=(int)(Mathsin(m314f/30-314f/2)25+ycenter);

lastxh=(int)(Mathcos((h30+m/2)314f/180-314f/2)18+xcenter);

lastyh=(int)(Mathsin((h30+m/2)314f/180-314f/2)18+ycenter);

lasts=s;

MediaTracker mt=new MediaTracker(this);//创建Tracke对象

clockp=getImage(getDocumentBase(),"休闲png");

gif1=getImage(getDocumentBase(),"gif1gif");

gif2=getImage(getDocumentBase(),"gif2gif");

clock6=getImage(getDocumentBase(),"clock6gif");

clock7=getImage(getDocumentBase(),"clock7gif");

mtaddImage(clockp,i++);

mtaddImage(gif1,i++);

mtaddImage(gif2,i++);

mtaddImage(clock6,i++);

mtaddImage(clock7,i++);

try{mtwaitForAll();}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();

calsetTime(dat);

//读取当前时间

s=(int)calget(CalendarSECOND);

m=(int)calget(CalendarMINUTE);

h=(int)calget(CalendarHOUR_OF_DAY);

today=dfformat(dat);

//指针位置

xs=(int)(Mathcos(s314f/30-314f/2)30+xcenter);

ys=(int)(Mathsin(s314f/30-314f/2)30+ycenter);

xm=(int)(Mathcos(m314f/30-314f/2)25+xcenter);

ym=(int)(Mathsin(m314f/30-314f/2)25+ycenter);

xh=(int)(Mathcos((h30+m/2)314f/180-314f/2)18+xcenter);

yh=(int)(Mathsin((h30+m/2)314f/180-314f/2)18+ycenter);

//设置字体和颜色

gsetFont(F);

gsetColor(fgcol);

gsetColor(fgcol2);

gsetColor(getBackground());

gfillRect(1,1,634,419);

gdrawImage(clockp,75,110,this);

gdrawImage(clock6,83,280,this);

gsetColor(fgcol2);

gsetColor(getBackground());

gsetColor(fgcol2);

//以数字方式显示年、月、日和时间

gdrawString(today,55,415);

gdrawLine(xcenter,ycenter,xs,ys);

gsetColor(fgcol);

//画指针

gdrawLine(xcenter,ycenter-1,xm,ym);

gdrawLine(xcenter-1,ycenter,xm,ym);

gdrawLine(xcenter,ycenter-1,xh,yh);

gdrawLine(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;

gdrawImage(gif2,115,35,this);

if(lasts!=s){

if(strike){

counter++;

dangerplay();//播放闹铃声

}

if(strike)strike=false;

else strike=true;

}

}

else {

counter=0;

flag=false;

}

}

else

gdrawImage(gif1,115,35,this);

int timedelta;//记录当前时间与闹铃定时的时差

Integer currh,currm,currs;//分别记录当前的时、分、秒

timeNow=new Date();

currh=new Integer(timeNowgetHours());

currm=new Integer(timeNowgetMinutes());

currs=new Integer(timeNowgetSeconds());

//判断是否要更新当前显示的时间,这样可以避免文本框出现频率闪动

if(currhintValue()!=IntegervalueOf(showhourgetText())intValue())

showhoursetText(currhtoString());

if(currmintValue()!=IntegervalueOf(showmingetText())intValue())

showminsetText(currhtoString());

if(currsintValue()!=IntegervalueOf(showsecgetText())intValue())

showsecsetText(currhtoString());

if(setalerm){ //判断是否设置了闹钟

//判断当前时间是否为闹钟所定的时间

if((currhintValue()==fixh)&&(currmintValue()==fixm)&&(currsintValue()==fixs))

clickflag=true;

timedelta=currmintValue()60+currsintValue()-fixm60-fixs;

if((timedelta<60)&&(clickflag==true)){ //若当前时间与闹钟相差时间达到60秒

chirpplay();

gdrawImage(clock7,83,280,this);

}

else{

chirpstop();

clickflag=false;

}

}

if(lasts!=s)

ipAuplay();//播放滴答声

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实例化

timerstart();

}

}

public void stop(){

timer=null;

}

public void run(){

while(timer!=null){

try{timersleep(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_bufgetGraphics();

offgclipRect(1,1,599,419);

paint(offg);

Graphics ong=getGraphics();

ongclipRect(1,1,599,419);

ongdrawImage(offscreen_buf,0,0,this);

}

public boolean action(Event evt,Object arg){ //按钮事件处理函数

if(evttarget instanceof Button){

String lable=(String)arg;

if(lableequals("开")){

setalerm=true;

//获取输入的时间

fixh=IntegervalueOf(sethourgetText())intValue();

fixm=IntegervalueOf(setmingetText())intValue();

fixs=IntegervalueOf(setsecgetText())intValue();

clickflag=false;

}

if(lableequals("关")){

setalerm=false;

if(chirp!=null)

chirpstop();

clickflag=false;

}

return true;

}

return false;

}

}

import javaawt;

import javaapplet;

import javaawtevent;

public class L07_D extends Applet implements ActionListener{

public void init() {

Button one;

Button two;

one = new Button("Button one");

two = new Button("Button two");

add(one);add(two);

oneaddActionListener(this);

twoaddActionListener(this);

}

public void actionPerformed(ActionEvent e) {

showStatus("One of my buttons was clicked");

}

}

Java可以编写嵌入在 Web 网页中运行的 Applet,是一种基于浏览器的客户端技术。Applet 是一种小型程序,可以在 Web 页面中嵌入执行,与 JavaScript、HTML 和 CSS 等前端技术共同构成了 Web 应用程序的前端部分。Applet 可以通过 Java 虚拟机在客户端上运行,可以与服务器进行交互,实现一些复杂的业务逻辑和交互效果。

Applet 在 Web 开发中有一定的局限性,因为它需要依赖于浏览器和 Java 插件,而且需要用户安装和启用 Java 插件。随着 Web 技术的发展和 HTML5、CSS3、JavaScript 等技术的不断升级,越来越多的 Web 应用程序开始采用前端框架和 Web API 技术,以实现更加灵活、响应更快的用户体验。

                                 

import javaapplet;

import javaawt;

import javaawteventActionEvent;

import javaawteventActionListener;

public class test extends Applet implements ActionListener

{

Label lb1,lb2;

TextField tf;

Button btn;

public void init()

{

lb1 = new Label("请输入一个整数:");

lb2 = new Label(" ");

tf = new TextField(10);

btn = new Button("判断");

setLayout(new FlowLayout());

add(lb1);

add(tf);

add(btn);

add(lb2);

btnaddActionListener(this);

setSize(200,200);

setVisible(true);

}

public void actionPerformed(ActionEvent e)

{

if(egetSource()==btn)

{

StringBuffer source = new StringBuffer(tfgetText());

sourcereverse();

String reverseString = new String(source);

if(reverseStringequals(tfgetText()))

lb2setText(tfgetText()+"是回文!");

else

lb2setText(tfgetText()+"不是回文!");

}

}

}

以上就是关于在线等——我做的网站需要一个漂亮的钟表......全部的内容,包括:在线等——我做的网站需要一个漂亮的钟表......、Java中Applet小程序的编写、1.Java是一种计算机程序语言,可以编写嵌入在Web网页中运行的是 __等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10206349.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存