麻烦大神f1 plus把TRejuvenating Sleep的音频给我发一下呗,谢谢谢谢!

谁有java游戏代码?发我邮箱,研究学习一下,谢谢 _百度知道
谁有java游戏代码?发我邮箱,研究学习一下,谢谢
提问者采纳
  /**************************************************************************  *1)主要部已经集象SnakeModel利用键盘控制实现操作  *************************************************************************/  import java.awt.*;  import java.awt.event.*;  import javax.swing.*;  import java.util.*;  //=============================================  //Main Class  //=============================================  public class GreedSnake implements KeyListener  {  JFrame mainF  Canvas paintC  JLabel labelS//计牌  SnakeModel snakeModel=// 蛇  public static final int canvasWidth=200;  public static final int canvasHeight=300;  public static final int nodeWidth=10;  public static final int nodeHeight=10;  //----------------------------------------------------------------------  //GreedSnake():初始化游戏界面  //----------------------------------------------------------------------  public GreedSnake()  {  //设置界面元素  mainFrame=new JFrame(&GreedSnake&);  Container cp=mainFrame.getContentPane();  labelScore=new JLabel(&Score:&);  cp.add(labelScore,BorderLayout.NORTH);  paintCanvas=new Canvas();  paintCanvas.setSize(canvasWidth+1,canvasHeight+1);  paintCanvas.addKeyListener(this);  cp.add(paintCanvas,BorderLayout.CENTER);  JPanel panelButtom=new JPanel();  panelButtom.setLayout(new BorderLayout());  JLabel labelH// 帮助信息  labelHelp=new JLabel(&PageUp, PageD&,JLabel.CENTER);  panelButtom.add(labelHelp,BorderLayout.NORTH);  labelHelp=new JLabel(&ENTER or R or S&,JLabel.CENTER);  panelButtom.add(labelHelp,BorderLayout.CENTER);  labelHelp=new JLabel(&SPACE or P for pause&,JLabel.CENTER);  panelButtom.add(labelHelp,BorderLayout.SOUTH);  cp.add(panelButtom,BorderLayout.SOUTH);  mainFrame.addKeyListener(this);  mainFrame.pack();  mainFrame.setResizable(false);  mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  mainFrame.setVisible(true);  begin();  }  //----------------------------------------------------------------------  //keyPressed():按键检测  //----------------------------------------------------------------------  public void keyPressed(KeyEvent e)  {  int keyCode=e.getKeyCode();  if(snakeModel.running) switch(keyCode)  {  case KeyEvent.VK_UP:  snakeModel.changeDirection(SnakeModel.UP);    case KeyEvent.VK_DOWN:  snakeModel.changeDirection(SnakeModel.DOWN);    case KeyEvent.VK_LEFT:  snakeModel.changeDirection(SnakeModel.LEFT);    case KeyEvent.VK_RIGHT:  snakeModel.changeDirection(SnakeModel.RIGHT);    case KeyEvent.VK_ADD:  case KeyEvent.VK_PAGE_UP:  snakeModel.speedUp();// 加速    case KeyEvent.VK_SUBTRACT:  case KeyEvent.VK_PAGE_DOWN:  snakeModel.speedDown();// 减速    case KeyEvent.VK_SPACE:  case KeyEvent.VK_P:  snakeModel.changePauseState();// 暂停或继续    default:  }  //重新始  if(keyCode==KeyEvent.VK_R || keyCode==KeyEvent.VK_S  || keyCode==KeyEvent.VK_ENTER)  {  snakeModel.running=  begin();  }  }  //----------------------------------------------------------------------  //keyReleased():空函数  //----------------------------------------------------------------------  public void keyReleased(KeyEvent e)  {  }  //----------------------------------------------------------------------  //keyTyped():空函数  //----------------------------------------------------------------------  public void keyTyped(KeyEvent e)  {  }  //----------------------------------------------------------------------  //repaint():绘制游戏界面(包括蛇食物)  //----------------------------------------------------------------------  public void update(Graphics g){  repaint();  }  void repaint()  {  Graphics g=paintCanvas.getGraphics();  //draw background  g.setColor(Color.WHITE);  g.fillRect(0,0,canvasWidth,canvasHeight);  //draw the snake  g.setColor(Color.BLACK);  LinkedList na=snakeModel.nodeA  Iterator it=na.iterator();  while(it.hasNext())  {  Node n=(Node)it.next();  drawNode(g,n);  }  // draw the food  g.setColor(Color.RED);  Node n=snakeModel.  drawNode(g,n);  updateScore();  }  //----------------------------------------------------------------------  //drawNode():绘画某结点(蛇身或食物)  //----------------------------------------------------------------------  private void drawNode(Graphics g,Node n)  {  g.fillRect(n.x*nodeWidth,n.y*nodeHeight,nodeWidth-1,nodeHeight-1);  }  //----------------------------------------------------------------------  //updateScore():改变计牌  //----------------------------------------------------------------------  public void updateScore()  {  String s=&Score: &+snakeModel.  labelScore.setText(s);  }  //----------------------------------------------------------------------  //begin():游戏始放置贪吃蛇  //----------------------------------------------------------------------  void begin()  {  if(snakeModel==null||!snakeModel.running)  {  snakeModel=new SnakeModel(this,canvasWidth/nodeWidth,  this.canvasHeight/nodeHeight);  (new Thread(snakeModel)).start();  }  }  //----------------------------------------------------------------------  //main():主函数  //----------------------------------------------------------------------  public static void main(String[] args)  {  GreedSnake gs=new GreedSnake();  }  }  /**************************************************************************  *要点析:  *1)数据结构:matrix[][]用存储图面信息没设置false  * 食物或蛇设置true;nodeArrayLinkedList用保存蛇每  * 节;food用保存食物位置;Node类保存每位置信息  *2)重要函数:  * changeDirection(int newDirection) 用改变蛇前进向且  * 保存部前进向其前进向已经用位置指明 其newDirection  * 必须原direction相反向所相反向值用同奇偶性测试  * 候使用direction%2!=newDirection%2 进行判断  * moveOn(),用更新蛇位置于前向部位置进行相应改变越界  * 结束;否则检测否遇食物(加部)或身体(结束);都没加部  * 掉尾部由于用LinkedList数据结构省相麻烦  *************************************************************************/  //----------------------------------------------------------------------  //Node:结点类  //----------------------------------------------------------------------  class Node  {      Node(int x,int y)  {  this.x=x;  this.y=y;  }  }  //----------------------------------------------------------------------  //SnakeModel:贪吃蛇模型  //----------------------------------------------------------------------  class SnakeModel implements Runnable  {  GreedS  boolean[][]// 界面数据保存数组  LinkedList nodeArray=new LinkedList();  N  int maxX;//宽度  int maxY;//度  int direction=2;//向  boolean running=  int timeInterval=200;// 间隔间(速度)  double speedChangeRate=0.75;// 速度改变程度  boolean paused=// 游戏状态  int score=0;  int countMove=0;  // UPDOWN偶数RIGHTLEFT奇数  public static final int UP=2;  public static final int DOWN=4;  public static final int LEFT=1;  public static final int RIGHT=3;  //----------------------------------------------------------------------  //GreedModel():初始化界面  //----------------------------------------------------------------------  public SnakeModel(GreedSnake gs,int maxX,int maxY)  {  this.gs=  this.maxX=maxX;  this.maxY=maxY;  matrix=new boolean[maxX][];  for(int i=0;i&maxX;++i)  {  matrix[i]=new boolean[maxY];  Arrays.fill(matrix[i],false);// 没蛇食物区置false  }  //初始化贪吃蛇  int initArrayLength=maxX&20 ? 10 : maxX/2;  for(int i=0;i&initArrayL++i)  {  int x=maxX/2+i;  int y=maxY/2;  nodeArray.addLast(new Node(x,y));  matrix[x][y]=// 蛇身处置true  }  food=createFood();  matrix[food.x][food.y]=// 食物处置true  }  //----------------------------------------------------------------------  //changeDirection():改变运向  //----------------------------------------------------------------------  public void changeDirection(int newDirection)  {  if(direction%2!=newDirection%2)// 避免冲突  {  direction=newD  }  }  //----------------------------------------------------------------------  //moveOn():贪吃蛇运函数  //----------------------------------------------------------------------  public boolean moveOn()  {  Node n=(Node)nodeArray.getFirst();  int x=n.x;  int y=n.y;  switch(direction)  {  case UP:  y--;    case DOWN:  y++;    case LEFT:  x--;    case RIGHT:  x++;    }  if((0&=x&&x&maxX)&&(0&=y&&y&maxY))  {  if(matrix[x][y])// 吃食物或者撞身体  {  if(x==food.x&&y==food.y)// 吃食物  {  nodeArray.addFirst(food);// 部加结点  //计规则与移度速度关  int scoreGet=(*countMove)/timeI  score+=scoreGet&0 ? scoreGet : 10;  countMove=0;  food=createFood();  matrix[food.x][food.y]=    }  // 撞身体  }  else//都没碰  {  nodeArray.addFirst(new Node(x,y));// 加部  matrix[x][y]=  n=(Node)nodeArray.removeLast();// 掉尾部  matrix[n.x][n.y]=  countMove++;    }  }  //越界(撞墙壁)  }  //----------------------------------------------------------------------  //run():贪吃蛇运线程  //----------------------------------------------------------------------  public void run()  {  running=  while(running)  {  try  {  Thread.sleep(timeInterval);  }catch(Exception e)  {    }  if(!paused)  {  if(moveOn())// 未结束  {  gs.repaint();  }  else//游戏结束  {  JOptionPane.showMessageDialog(null,&GAME OVER&,  &Game Over&,RMATION_MESSAGE);    }  }  }  running=  }  //----------------------------------------------------------------------  //createFood():食物及放置点  //----------------------------------------------------------------------  private Node createFood()  {  int x=0;  int y=0;  do  {  Random r=new Random();  x=r.nextInt(maxX);  y=r.nextInt(maxY);  }while(matrix[x][y]);  return new Node(x,y);  }  //----------------------------------------------------------------------  //speedUp():加快蛇运速度  //----------------------------------------------------------------------  public void speedUp()  {  timeInterval*=speedChangeR  }  //----------------------------------------------------------------------  //speedDown():放慢蛇运速度  //----------------------------------------------------------------------  public void speedDown()  {  timeInterval/=speedChangeR  }  //----------------------------------------------------------------------  //changePauseState(): 改变游戏状态(暂停或继续)  //----------------------------------------------------------------------  public void changePauseState()  {  paused=!  }  }
其他类似问题
java游戏的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁急需要广州小学五年级的英语单词麻烦帮一下~谢谢_百度知道
急需要广州小学五年级的英语单词麻烦帮一下~谢谢
我现急用五级册单词麻烦帮帮我知道请写蓝色单词黑色单词请
PEP五级册四单词词汇表 Unit 1 Young (轻) funny (滑稽笑) tall (高) strong (强壮) kind (蔼、亲切) old () short (矮)thin (瘦) Mr (先) like (像、喜欢) strict (严格) smart (聪明、巧妙) active (积极、跃) quiet (安静、文静)very (、非) but () Unit 2 Mondy (星期) Tuesday (星期二) Wednesday (星期三) Thursday (星期四) Friday (星期五) Saturday (星期六) Sunday (星期) day () have (、吃) on (…..候) do homework (做作业) watch TV (看电视) read books (读书) Unit 3 eggplant (茄) fish (鱼) green beans (青豆) tofu (豆腐) potato (土豆) tomato (西红柿) for () lunch (餐) we (我) tasty (吃) sweet (甜) sour (酸) fresh (新鲜) salty (咸) favourite (喜欢) they are () fruit (水) grape (葡萄) Unit 4 Cook the meals (倒垃圾) water the flowers (浇花) sweep the floor (扫) clean the bedroom (打扫卧室) make the bed (铺床) set the table (摆饭桌) wash the clothes (洗碗碟) do the dishes (收拾衣服) use a computer (使用计算机 Unit 5 curtain (空调) trash bin (垃圾箱) closet (壁橱) mirror (镜) end table (床柜) bedroom (卧室) kitchen (厨房) bathroom (卫间) living room (客厅) in (…面) on (…面) under (…面) near (..旁边) behind (…边) clothes (衣服) Unit 6 river (河流) flower (花) grass (草) lake (湖泊) forest (森林) path (路) pake (公园) picture (照片) hourse (房) bridge (桥) tree (树) road (公路) building (建筑物) clean (干净) PEP五级册四单词词汇表 Unit 1 do morning exercises(晨练) eat breakfast(吃早饭) have english class(英语课) play sports(进行体育运) eat dinner(吃晚饭) when(候) evening(夜晚;晚) get up(起床) at(……点钟) usually(通;般) noon(午) climb mountains(爬山) go shopping(购物;买东西) play the piano(弹钢琴) visit grandparents(看望祖父母) go hiking(远足) weekend(周末) often(经) sometimes(候) Unit 2 spring(春) summer(夏) fall(秋) winter(冬) season季节) which(哪) best(;极) swim(游泳) fly kites(放风筝) skate(滑冰;滑冰鞋) make a snowman(堆雪) plant trees(种树) why() because() sleep(睡觉) Unit 3 Jan./January(月) Feb./February(二月) Mar./March(三月) Apr./April(四月) May(五月) June(六月) July(七月) Aug./Augest(八月) Sept./September(九月) Oct./October(十月) Nov./November(十月) Dec./December(十二月) birthday() uncle(叔叔;舅舅) her() date(期) Unit 4 draw pictures(画画) cook dinner(做饭) read a book(看书)answer the phone(接电) mom(妈妈) listen to music9(听音乐) clean the room(打扫房间) write a letter(写信) write an e-mail(写电邮件) grandpa(爷爷;外公) study(书房) Unit 5 fly(飞) jump(跳) walk(走) run(跑) swim(游泳) kangaroo(袋鼠) sleep(睡觉) climb(往爬) fight(打架) swing(荡;荡秋千) drink water(喝水) Unit 6 take pictures(照相) watch insects(观察昆虫) pick up leaves(采摘树叶) do an experiment(做实验) catch butterfly(捉蝴蝶) honey(蜂蜜) count insects(数昆虫) collect leaves(收集树叶) wtite a report(写报告) play chess(棋) have a picnic(举行野餐)
其他类似问题
英语单词的相关知识
其他3条回答
PEP五年级上册四会单词词汇表Unit 1Young (年轻的)
funny (滑稽可笑的)
tall (高的)
strong (强壮的)
kind (和蔼的;亲切的)
old (年老的)
short (矮的)
Mr (先生)
like (像;喜欢)
strict (严格的)
smart (聪明的;巧妙的)
active (积极的;活跃的)
quiet (安静的;文静的)
very (很;非常)
but (但是)Unit 2Monday (星期一)
Tuesday (星期二)
Wednesday (星期三)
Thursday (星期四)
Friday (星期五)
Saturday (星期六)
Sunday (星期天)
day (天;日子)
have (有;吃)
on (在…..时候)
homework (做作业)
TV (看电视)
books (读书)
Unit 3eggplant (茄子)
fish (鱼)
green beans (青豆)
tofu (豆腐)
potato (土豆)
tomato (西红柿)
for (为;给)
lunch (中餐;午饭)
we (我们)
tasty (好吃的)
sweet (甜的)
sour (酸的)
fresh (新鲜的)
salty (咸的)
favourite (最喜爱的;特别喜爱的)
they are (他们是)
fruit (水果)
grape (葡萄)Unit 4Cook the meals (倒垃圾)
water the flowers (浇花)
sweep the floor (扫地)
clean the bedroom (打扫卧室)
make the bed (铺床)
set the table (摆饭桌)wash the clothes (洗碗碟)
do the dishes (收拾衣服)
use a computer (使用计算机)Unit 5curtain (空调)
trash bin (垃圾箱)
closet (壁橱)
mirror (镜子)
end table (床头柜)
bedroom (卧室)
kitchen (厨房)
bathroom (卫生间)
living room (客厅)
in (在…里面)
on (在…上面)
under (在…下面)
near (在..旁边)
behind (在…后边)
clothes (衣服)Unit 6river (河流)
flower (花)
grass (草)
lake (湖泊)
forest (森林)
path (路)
park (公园)
picture (照片)
house (房子)
bridge (桥)
tree (树)
road (公路)
building (建筑物)
clean (干净的)PEP五年级下册四会单词词汇表Unit 1do morning exercises(晨练)
eat breakfast(吃早饭)
have English class(上英语课)
play sports(进行体育运动)
eat dinner(吃晚饭)
when(什么时候)
evening(夜晚;晚上)
get up(起床)
at(在…点钟)
usually(通常;一般)
noon(中午)
climb mountains(爬山)
go shopping(购物;买东西)
play the piano(弹钢琴)
visit grandparents(看望祖父母)
go hiking(去远足)
weekend(周末)
often(经常)
sometimes(有时候)Unit 2spring(春天)
summer(夏天)
fall(秋天)
winter(冬天)
season季节)
which(哪一个)
best(最;极)
swim(游泳)
fly kites(放风筝)
skate(滑冰;滑冰鞋)
make a snowman(堆雪人)
plant trees(种树)
why(为什么)
because(因为)
sleep(睡觉)Unit 3Jan./January(一月)
Feb./February(二月)
Mar./March(三月)
Apr./April(四月)
May(五月)
June(六月)
July(七月)
Aug./August(八月)
Sept./September(九月)Oct./October(十月)
Nov./November(十一月)
Dec./December(十二月)
birthday(生日)
uncle(叔叔;舅舅)
her(她的)
date(日期)Unit 4aw pictures(画画)
cook dinner(做饭)
read a book(看书)
answer the phone(接电话)
listen to music9(听音乐)
clean the room(打扫房间)
write a letter(写信)
write an e-mail(写电子邮件)
mom(妈妈)
grandpa(爷爷;外公)
study(书房)Unit 5fly(飞)
jump(跳)
walk(走)
swim(游泳)
kangaroo(袋鼠)
sleep(睡觉)
climb(往上爬)
fight(打架)
swing(荡;荡秋千)
drink water(喝水)Unit 6take pictures(照相)
watch insects(观察昆虫)
pick up leaves(采摘树叶)
do an experiment(做实验)
catch butterfly(捉蝴蝶)
honey(蜂蜜)
count insects(数昆虫)
leaves(收集树叶)
write a report(写报告)
play chess(下棋)
have a picnic(举行野餐)
到广州上学网看看吧,有“小学在读”版块,有很多家长交流你可以去看看吧
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁今天晚上必须求到JAVA闹钟实训报告,老婆急用。各位大哥大姐有的就麻烦发一下.谢谢了_百度知道
今天晚上必须求到JAVA闹钟实训报告,老婆急用。各位大哥大姐有的就麻烦发一下.谢谢了
我有更好的答案
按默认排序
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= //创建线程timer Image gif1; //clockp:闹钟的外壳,闹铃和报时物 boolean setflag=false,stopflag=false,cancelflag= P //获取声音文件 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= } }; private ActionListener cancelli=new ActionListener() { public void actionPerformed(ActionEvent e) { setflag= } }; 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提供的是一个日历式的东东,上面又多了很多的参数,是方便操作了不少。而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= Date timeN Color fgcol=Color. Color fgcol2=Color.darkG Color backcolor=Color. Label hlabel2,mlabel2,slabel2;//显示时间单位时所用的标签(时、分、秒)
int s,m,h; TextField sethour,setmin,//显示当前时间文本框和定时文本框 //在Applet程序中,首先自动调用初始化完成必要的初始化工作,紧接着自动调用start,在进入执行程序和返回到该页面时被调用,而从该页面转到别的页面时,stop被调用,关闭浏览器时,执行destroy。 public void init()//初始化方法 { 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); note1.setBounds(30,100,60,20); note1.setBackground(backcolor); note1.setForeground(Color.black); //定时用的文本框(时、分、秒) sethour=new TextField(&00&,5); setmin=new TextField(&00&,5); setsec=new TextField(&00&,5); hlabel2=new Label(); mlabel2=new Label(); slabel2=new Label(); //定时的小时文本框的位置、大小 setpanel.add(sethour); sethour.setBounds(fieldx,fieldy2,fieldw,fieldh); sethour.setBackground(Color.white); //在文本框后加入单位“时” setpanel.add(hlabel2); hlabel2.setText(&h&); hlabel2.setBackground(backcolor); hlabel2.setForeground(Color.black); hlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20); fieldx=fieldx+ //定时的分钟文本框的位置、大小 setpanel.add(setmin); setmin.setBounds(fieldx,fieldy2,fieldw,fieldh); setmin.setBackground(Color.white); //在文本框后加入单位“分” setpanel.add(mlabel2); mlabel2.setText(&m&); mlabel2.setBackground(backcolor); mlabel2.setForeground(Color.black); mlabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20); fieldx=fieldx+ //定时的秒文本框的位置、大小 setpanel.add(setsec); setsec.setBounds(fieldx,fieldy2,fieldw,fieldh); setsec.setBackground(Color.white); //在文本框后加入单位“秒” setpanel.add(slabel2); slabel2.setText(&s&); slabel2.setBackground(backcolor); slabel2.setForeground(Color.black); slabel2.setBounds(fieldx+fieldw+3,fieldy2,14,20); //设置闹钟控制按钮(on,off) setpanel.add(cancelbutton); setpanel.add(setbutton); setpanel.add(stopbutton); cancelbutton.setBounds(90,180,40,20); setbutton.setBounds(140,180,40,20); stopbutton.setBounds(522,180,40,20); setbutton.addActionListener(setli); cancelbutton.addActionListener(cancelli); stopbutton.addActionListener(stopli); stopbutton.setVisible(false); //将面板加入当前容器中,并设置面板的大小和背景色 add(setpanel); setpanel.setBounds(300,1,250,420); setpanel.setBackground(backcolor); /*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);//为给定组件创建一个跟踪媒体的MediaTracker对象,把图片添加到被跟踪的图片组 //Java允?Sapplet??HTML所在的位置(decument base)下?d?Y料,也允?Sapplet?钠涑淌酱a所在的位置(code base)下?d?Y料。藉由呼叫getDocumentBase()?cgotCodeBase()可得到URL物件。?@些函?????湍阏业侥阆胂螺d的?n案的位置
//clockp=getImage(getDocumentBase(),&11.png&); gif1=getImage(getCodeBase(),&2.gif&); //i为id号 mt.addImage(gif1,i++); try { mt.waitForAll(); } catch(InterruptedException e) {};//等待加载结束 resize(600,420);//设置窗口大小 } //窗口显示有改变的时候调用paint public void paint(Graphics g) {//重写paint()方法 int xh,yh,xm,ym,xs,ys,strike_ int xcenter, S 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)*12+xcenter); yh=(int)(Math.sin((h*30+m/2)*3.14f/180-3.14f/2)*12+ycenter); //设置字体和颜色 g.setFont(F); //前景色 g.setColor(getBackground()); //取背景色的 g.drawImage(gif1,75,110,this); //以数字方式显示年、月、日和时间 g.drawString(today,55,415); //画指针 g.drawLine(xcenter,ycenter,xs,ys); g.drawLine(xcenter,ycenter-1,xm,ym); //(x1,y1,x2,y2) g.drawLine(xcenter-1,ycenter,xm,ym); g.drawLine(xcenter,ycenter-1,xh,yh); g.drawLine(xcenter-1,ycenter,xh,yh); //记录当前时间与闹铃定时的时差 Integer currh,currm,//分别记录当前的时、分、秒 Date dat2=new Date(); cal2.setTime(dat2); //读取当前时间 currh=(int)cal2.get(Calendar.SECOND); currm=(int)cal2.get(Calendar.MINUTE); currs=(int)cal2.get(Calendar.HOUR_OF_DAY); //这样做的话说我API已过时 //timeNow=new Date(); //currh=new Integer(timeNow.getHours()); //currm=new Integer(timeNow.getMinutes()); //currs=new Integer(timeNow.getSeconds()); if(setflag) { //判断是否设置了闹钟 //判断当前时间是否为闹钟所定的时间 if((currh.intValue()==Integer.valueOf(sethour.getText()).intValue())&&(currm.intValue()==Integer.valueOf(setmin.getText()).intValue())&&(currs.intValue()==Integer.valueOf(setsec.getText()).intValue())) { ring.play(); g.drawImage(gif1,83,280,this); stopbutton.setVisible(true); } timedelta=currm.intValue()*60+currs.intValue()-Integer.valueOf(setmin.getText()).intValue()*60-Integer.valueOf(setsec.getText()).intValue(); if((timedelta&=30)) { //若当前时间与闹钟相差时间超过30秒,闹钟自动停 ring.stop(); //清除的方法 g.clearRect(83,280,20,30); } } dat= } public void start() { if(timer==null) { timer=new Thread(this);//将timer实例化 timer.start(); } } public void stop() { timer= } //给创建线程后start之后自动执行的函数 public void run() { //在run()方法中,调用repaint()方法,以重绘小程序区,进行时钟显示的更新。接着调用sleep方法让当前线程(也就是我们创建的线程clockthread)睡眠1000毫秒,因为我们每秒钟要更新一下显示,所以让它睡眠1秒 while(timer!=null) { try { timer.sleep(1000); } catch(InterruptedException e) {} //调用repaint时,会首先清除掉paint方法之前的画的内容,再调用paint方法 repaint();//刷新画面 } timer= } //当AWT接收到一个applet的重绘请求时,它就调用applet的 update(),默认地,update() 清除applet的背景,然后调用 paint()。重载 update(),将以前在paint()中的绘图代码包含在update()中,从而避免每次重绘时将整个区域清除 //有两种方法可以明显地减弱闪烁:重载 update()或使用双缓冲。 //使用双缓冲技术:另一种减小帧之间闪烁的方法是使用双缓冲,它在许多动画Applet中被使用。其主要原理是创建一个后台图像,将需要绘制的一帧画入图像,然后调用DrawImage()将整个图像一次画到屏幕上去;好处是大部分绘制是离屏的,将离屏图像一次绘至屏幕上比直接在屏幕上绘制要有效得多,大大提高做图的性能。 //
双缓冲可以使动画平滑,但有一个缺点,要分配一张后台图像,如果图像相当大,这将需要很大一块内存;当你使用双缓冲技术时,应重载 update()。 public void update(Graphics g) { Image offscreen_buf= //采用双缓冲技术的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); } /** Creates a new instance of AlarmClock */ }
其他类似问题
闹钟的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 大神f1 plus 的文章

 

随机推荐