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

📄 timescroll.java

📁 本程序实现了日历与时间功能
💻 JAVA
字号:
import java.applet.*;import java.awt.*;import java.net.*;import java.util.*;import java.io.*; class TimeAndDateFormatter {    String formattedDate;    String  daysOfWeek[]   = { "星期日","星期一","星期二","星期三","星期四","星期五","星期六" };    String  monthsOfYear[] = { "一月","二月","三月","四月","五月","六月",                               "七月","八月","九月","十月","十一月","十二月"  };    TimeAndDateFormatter( Date date, String title ) {        int h = date.getHours();        int m = date.getMinutes();        int s = date.getSeconds();        int dy = date.getDay();        int dt = date.getDate();        int mn = date.getMonth();        int yr = date.getYear();        String hours, minutes, seconds, am_pm;        String day, numericalDate, month, year;        if( h == 0 ) {            hours = new String( "12"  );            am_pm = new String( "AM" );        } else if( h > 12 ) {            hours = new String( "" + (h-12) );            am_pm = new String( "PM"     );        } else if( h == 12 ) {            hours = new String( "12" );            am_pm = new String( "PM"  );         } else {            hours = new String( "" + h );            am_pm = new String( "AM"  );        }        if( m < 10 ) {            minutes = new String( "0" + m );        } else {            minutes = new String( ""  + m );        }        if( s < 10 ) {            seconds = new String( "0" + s );        } else {            seconds = new String( ""  + s );        }        day = daysOfWeek[ dy ];                numericalDate = new String( "" + dt );        month = monthsOfYear[ mn ];        year  = new String( "" + (1900 + yr) );        formattedDate = new String( day + ", " +                                    month + " " +                                    numericalDate + "日 , " +                                                                        year + " 年 " + title + "  " +                                    hours   + ":" +                                    minutes + ":" +                                    seconds + " " + am_pm                                    );    }    public String toString() {        return formattedDate;    }}public class TIMESCROLL extends Applet implements Runnable   {    private Thread clock;    private String font_name, title, datestring;			    private int height, width, font_size;		    private Font wordFont;    private FontMetrics wordMetrics;    private int textcolor, backcolor, bordercolor;    private int stringx, stringy;    private int delay, s_width;    TimeAndDateFormatter formattedTimeAndDate;    private Image offI;    private Graphics offG;         public void init()     {      String temp;      height = size().height;	      width = size().width;      offI = createImage(width,height);      offG = offI.getGraphics();      delay = 30;     temp=getParameter("title");     title = (temp==null) ? " " : temp;     temp=getParameter("font");     font_name= (temp==null) ? "TimesRoman" : temp;     temp = getParameter("fontsize");     font_size= (temp==null) ? 12 : Integer.parseInt( temp );     						     wordFont = new Font(font_name, Font.BOLD, font_size);     if (wordFont == null)       wordFont = getFont();     wordMetrics = getFontMetrics (wordFont);    temp = getParameter("Fore");    textcolor = (temp==null) ? 0x000000 : Integer.parseInt(temp, 16);    temp = getParameter("backcolor");    backcolor= (temp==null) ? 0xffffff : Integer.parseInt(temp, 16);    temp = getParameter("Back");    bordercolor = (temp==null) ? backcolor : Integer.parseInt(temp, 16); }  public void start()      {       clock = new Thread(this); 	       clock.start();	     }	  public void stop()     {      clock.stop();    }    public void run()       {       Thread.currentThread().setPriority(Thread.MIN_PRIORITY);	       int x=width;      while(true)        {         Date date = new Date();          formattedTimeAndDate =            new TimeAndDateFormatter( date, title );          datestring = formattedTimeAndDate.toString();                    offG.setFont(wordFont);			          offG.setColor(new Color(backcolor));		          offG.fillRect(0,0,width,height);          offG.setColor(new Color(textcolor));          s_width = wordMetrics.stringWidth(datestring);          stringy = (height - (wordMetrics.getHeight()-wordMetrics.getLeading()))/2 + (wordMetrics.getHeight()-wordMetrics.getLeading()-wordMetrics.getDescent());		           stringx = (width - s_width)/2;          offG.drawString (datestring, x, stringy);          offG.setColor(new Color(bordercolor));          offG.drawRect(0, 0, width-1, height-1);	                    repaint();          x--;          if(x == stringx)          {             try              {                Thread.sleep(5000);             }              catch( InterruptedException ex ){}           }                    if(x <-width)          {            x = width;          }          try {                Thread.sleep(delay);              }           catch( InterruptedException e )             {}        }        }  public void update (Graphics g)     {      paint(g);    }  public synchronized void paint(Graphics g)     {       g.drawImage(offI,0,0,this);    }		  public void paintApplet(Graphics g)     {					}}

⌨️ 快捷键说明

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