⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applet1.java~1~

📁 用jbuilder开发的一个网络时钟
💻 JAVA~1~
字号:
package webclock;import java.util.Date;import java.awt.*;import java.awt.event.*;import java.applet.*;public class Applet1 extends Applet implements Runnable{  private boolean isStandalone = false;  //tianjia  Date timenow;  Clock myClock;  Thread clockthread = null;  //Get a parameter value  public String getParameter(String key, String def) {    return isStandalone ? System.getProperty(key, def) :      (getParameter(key) != null ? getParameter(key) : def);  }  //Construct the applet  public Applet1() {  }  //Initialize the applet  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception {  }  //Get Applet information  public String getAppletInfo() {    return "Applet Information";  }  //Get parameter info  public String[][] getParameterInfo() {    return null;  }  //run方法  public  void  run(){    while(true){      repaint();      try{          Thread.sleep(1000);      }      catch(InterruptedException e){}    }  }  public void start(){    if(clockthread == null){      clockthread = new Thread(this);      clockthread.start();    }  }  public void stop(){    clockthread.stop();    clockthread = null;  }  public void paint(Graphics g){    timenow = new Date();    myClock = new Clock(timenow.getHours(),timenow.getMinutes(),timenow.getSeconds());    g.drawString(timenow.toString(),25,240);    myClock.show(g,100,100,100);  }}  class  Clock  {    Clock(int hrs, int  min, int sec)    {      hour = hrs%12;      minute = min;      second = sec;    }    void show(Graphics  g,int cx,int cy,int rad)    {      int hrs_len = (int)(rad*0.5),          min_len = (int)(rad*0.6),          sec_len = (int)(rad*0.9);      double  theta;      g.drawOval(cx-rad,cy-rad,rad*2,rad*2);      theta = (double)(hour *60*60+minute*60+second)/43200.0*2.0*Math.PI;      drawNiddle(g,Color.blue,cx,cy,hrs_len,theta);      theta = (double)(minute*60+second)/3600.0*2.0*Math.PI;      drawNiddle(g,Color.red,cx,cy,min_len,theta);      theta = (double)(second)/60.0*2.0*Math.PI;      drawNiddle(g,Color.green,cx,cy,sec_len,theta);      }      private void drawNiddle(Graphics g,Color c,int x,int y,int len,double theta){        int ex = (int)(x+len*Math.sin(theta));        int ey = (int)(y-len*Math.cos(theta));        g.setColor(c);        g.drawLine(x,y,ex,ey);      }      int hour,minute,second; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -