Topic: Javascript Stardate Clock Pages that link to <a href="https://ozoneasylum.com/backlink?for=29187" title="Pages that link to Topic: Javascript Stardate Clock" rel="nofollow" >Topic: Javascript Stardate Clock\

 
Author Thread
Mr_Wizard
Obsessive-Compulsive (I) Inmate

From: OZONE Asylum
Insane since: Apr 2007

IP logged posted posted 05-05-2007 09:34 Edit Quote

I run a webhosting/development service, and I have a client requesting a Stardate clock (in both a "Federation" and a "Klingon" format) on his site to show a future date in a Stardate format. However, I don't know Javascript (and i'm totaly guessing i'd have to use it) so how do I go about creating one. I started off with:

code:
import java.awt.*;
import java.applet.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.lang.Math;
import java.lang.Integer;

/**

Applet displays future stardate
*/

public class stardate extends Applet implements Runnable {


 Image buffer;

 Graphics doublebuffer;
 int height, width;
 String beforePoint,afterPoint;
 boolean preWarp = false;
 Thread mythread;
 Image glyphs[],beforeWarp,point,Background;
 /*
   specify interval between updates ( roughly )
   do not trash target system */
 static final int RRATE = 1000;
 /* 
    gregorian date of descent of warp technilogy -
    zero point in stardate calculation
 */
 GregorianCalendar warpStart= new GregorianCalendar(2323,0,1);

 public void init () {

  showStatus("loading glyphs...");
 
  // load images
  point = this.getImage(this.getCodeBase(),"stardateP.gif");
  beforeWarp = this.getImage(this.getCodeBase(),"stardateBW.gif");
  Background= this.getImage(this.getCodeBase(),"stardateBG.gif");

  
  glyphs= new Image[10];
  glyphs[0] = this.getImage(this.getCodeBase(),"stardate0.gif");
  glyphs[1] = this.getImage(this.getCodeBase(),"stardate1.gif");
  glyphs[2] = this.getImage(this.getCodeBase(),"stardate2.gif");
  glyphs[3] = this.getImage(this.getCodeBase(),"stardate3.gif");
  glyphs[4] = this.getImage(this.getCodeBase(),"stardate4.gif");
  glyphs[5] = this.getImage(this.getCodeBase(),"stardate5.gif");
  glyphs[6] = this.getImage(this.getCodeBase(),"stardate6.gif");
  glyphs[7] = this.getImage(this.getCodeBase(),"stardate7.gif");
  glyphs[8] = this.getImage(this.getCodeBase(),"stardate8.gif");
  glyphs[9] = this.getImage(this.getCodeBase(),"stardate9.gif");
 
  /* used deprecated API to be polite to pre 1.1.6 java */
  width = bounds().width;
  height= bounds().height;  
  
  buffer = createImage(width,height);
  doublebuffer = buffer.getGraphics();

  showStatus("done...");
 }

 public void paint (Graphics g) {

 
  computeStardate();
 
  // draw rectangle filled white
  //doublebuffer.setColor(Color.white);
  //doublebuffer.fillRect(0,0,width,height);
  
  // draw background image
  doublebuffer.drawImage(Background,0,0,this);

  int i,index;
  int cumulativeWidth = 0;
  for(i=0; i < beforePoint.length(); i++) {
     index = Character.digit(beforePoint.charAt(i),10);
     doublebuffer.drawImage(glyphs[index],cumulativeWidth,0,this);
     cumulativeWidth = cumulativeWidth + glyphs[index].getWidth(this);
  }
  doublebuffer.drawImage(point,cumulativeWidth,0,this);
  cumulativeWidth = cumulativeWidth + point.getWidth(this);  
  // draw after decimal point
  for(i=0; i < afterPoint.length(); i++) {
     index = Character.digit(afterPoint.charAt(i),10);
     doublebuffer.drawImage(glyphs[index],cumulativeWidth,0,this);
     cumulativeWidth = cumulativeWidth + glyphs[index].getWidth(this);
  }
  if(preWarp) {
     doublebuffer.drawImage(beforeWarp,cumulativeWidth,0,this);	
  }


  g.drawImage(buffer,0,0,this);

 }

 public void update (Graphics g) {
  paint(g);
 }

/**
	compute future stardate
  	mybe just subclass GregorianCalendar ?
*/
  public void computeStardate () {
  int YY;
  double T,DDD;
  GregorianCalendar current = new GregorianCalendar();

  YY = current.get(Calendar.YEAR) - warpStart.get(Calendar.YEAR);
  
  if(current.before(warpStart)) {
	preWarp= true;
	YY = Math.abs(YY);
  }

  if(current.isLeapYear(current.get(Calendar.YEAR))) {
	DDD = (current.get(Calendar.DAY_OF_YEAR)-1)/366.0;
  }
  else {
	DDD = (current.get(Calendar.DAY_OF_YEAR)-1)/365.0;
  }
  T = (current.get(Calendar.HOUR_OF_DAY) * 3600.0 + 
		         current.get(Calendar.MINUTE)*60.0 + 
			 current.get(Calendar.SECOND)) / 86400.0;     	
  /* now we compose our strings - chop first 2 chars start of year fraction*/
  beforePoint = Integer.toString(YY) + Double.toString(DDD).substring(2);
  /* trim string to 6 chars */
  if(beforePoint.length() > 6)
	beforePoint = beforePoint.substring(0,6);
  /* the same - also specify desired precision */
  afterPoint =  Double.toString(T).substring(2);
  if(afterPoint.length() > 5)
	afterPoint = afterPoint.substring(0,5);

}




 public void start () {
 

 showStatus("Stardate syncronized...");
  mythread = new Thread(this);
   if (mythread != null) {
    mythread.start();
   }
 }

 public void run () {
  while (true) {
   repaint();
    try {
     Thread.sleep(RRATE);     
    } catch (Exception exc) {};
   }
 }

 public void stop () {
 
  showStatus("Quitting applet");
   if (mythread != null) {
    mythread.stop();
    mythread = null;
    }
  }

 public void destroy () {
  showStatus("Freeing resources");
 }

}



I upload all the images into the base directory of the site, and edit the <body> </body> tags accordinly and I shows an error message saying "Syntax error" Where do I go from here?

The Wizard of Atari-Sega-Nendo-Photoshop, admitted for making too many photo shop projects.


Edit Tyberius Prime: added missing code tags.

(Edited by Tyberius Prime on 05-05-2007 13:40)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 05-05-2007 13:39 Edit Quote

you learn the difference between java and javascript.

Then you need to research how a stardate is actually calculated, and pour that into java script ( what you have there is java, and not only will it require compilation on your side, it requires an appropriate run time on the client and about a gazillion times more resources than a javascript solution.

If you want to use this, and have a compiled version of it ( read: a jar file), show us what you put in your <body>.

So long,
->Tyberius Prime

(Edited by Tyberius Prime on 05-05-2007 13:39)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 05-05-2007 14:38 Edit Quote

Also, image swapping is a bad idea. It can generate some reflow if the browser's layout engine is not really well optimized, not to mention the hassle of having to preload the images to avoid further useless connections.

Use something like CSS sprites, and check the entries submitted to the March 2005 - 20 lines JavaScript contest - XXX. Mine uses CSS sprites and fits in 8 lines ( at least 2 more lines can be removed without obfuscating the code ).

Hope that helps,

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 05-05-2007 19:44 Edit Quote

My point about the number of lines is that making that kind of clock is straight forward.

Mr_Wizard
Obsessive-Compulsive (I) Inmate

From: OZONE Asylum
Insane since: Apr 2007

IP logged posted posted 05-05-2007 21:24 Edit Quote
quote:

poi said:

Also, image swapping is a bad idea. It can generate some reflow if the browser's layout engine is not really well optimized, not to mention the hassle of having to preload the images to avoid further useless connections.Use something like CSS sprites, and check the entries submitted to the March 2005 - 20 lines JavaScript contest - XXX. Mine uses CSS sprites and fits in 8 lines ( at least 2 more lines can be removed without obfuscating the code ).Hope that helps,



<body>
Êþº¾  -P è ¼ Ú Ü à â í î ò ó ô õ ö ý  
57<>CO ù"#$%&'()*+,-./0123C
 
/ 
% ?
/
- ?
* ?
+ ? 0 ?
( ? 0 ?
+ ?
/ ? 0 ?
 ? 0 ?
* ?
0
 ? 0 0
$ ? 0 ?
?
. ?
 ?
! ?
 ?
 ?
! ? 0 ? " ? 0 ? 0 ? 0 0 ?
% ?
' ?
/  
* ¡ 0 ¢ , £
0 ¤ 0 ¥ 0 ¦ 0 §
# ¨
# © 0 ª
 «
 ¬
- ­
- ®
- ¯
* °
* ±
+ ²
' ³
' ´
* µ
' ¶ 0 · " ¸ 0 ¸ 0 ¹ 0 º 0 » è@N @vÐ @và @¬ @õ Û Â Û Å Û Ì Û Ô Û Ø Ý ç ú Ç û é ü × þ Ó ÿ é  ¿  ç  Æ  Â  Ê  ä  ä  Ä 
æ  Ï  Ç  Á  ¾  Ù  Ö  Ð  ø  ã  ã  é  é  ½ ! É 4 ½ 6 ê 8 è 9 Î : ç ; ÷ < ã = Ò = Ø > ã ? Â A Ø B Í E Â F Â G È G Ë H À H È H Ë J Ñ J Õ K ë L ã M ä N ä O ã 4 radix to be used in stardate display,defaults to 10 ()I ()Ljava/awt/Graphics; ()Ljava/awt/Rectangle; ()Ljava/lang/String; ()Ljava/net/URL; ()V ()[[Ljava/lang/String; (CI)I (D)V (I)C (I)I (I)Ljava/lang/String; (I)Z (II)Ljava/awt/Image; (II)Ljava/lang/String; (III)V (J)V (Ljava/awt/GraphicsV 3(Ljava/awt/Image;IILjava/awt/image/ImageObserverZ !(Ljava/awt/image/ImageObserverI &(Ljava/lang/ObjectLjava/lang/String; (Ljava/lang/ObjectV (Ljava/lang/ObjectZ (Ljava/lang/RunnableV '(Ljava/lang/StringLjava/lang/Integer; &(Ljava/lang/StringLjava/lang/String; ,(Ljava/lang/StringLjava/lang/StringBuffer; (Ljava/lang/StringV 2(Ljava/net/URL;Ljava/lang/StringLjava/awt/Image; .gif <init> BG
Background Code
ConstantValue ±Copyright by Konstantin Priblouda 1999, all rights reserved
This applet display current stardate in various formats
This applet is licensed to you under GNU GPL ( www.gnu.org )
Exceptions Freeing resources I J LineNumberTable Ljava/awt/Graphics; Ljava/awt/Image; Ljava/io/PrintStream; Ljava/lang/String; Ljava/lang/Thread; Ljava/util/GregorianCalendar; LocalVariables P Quitting applet RRATE
SGILineNumber
SourceFile Stardate syncronized... String 'Unable to get precision - fallback to 5 $Unable to get radix - fallback to 10 5Unable to get year fraction precision - fallback to 3 Z [Ljava/awt/Image; [Ljava/lang/String; abs
afterPoint append 2base name of a glyph image, defaults to 'stardate' before beforePoint bounds buffer charAt computeStardate createImage dayFractionMultiplyer dayFractionPadder destroy digit done... doublebuffer drawImage fallback to '.gif' fallback to 'stardate' get
getAppletInfo getCodeBase getGraphics getImage getParameter getParameterInfo getWidth glyphs height 9how many digits to represent year fraction - 3 is default -how many digits use after point defaults to 5 i imageType imagename imagetype init int intValue
isLeapYear java/applet/Applet java/awt/Component java/awt/Graphics java/awt/Image java/awt/Rectangle java/io/PrintStream java/lang/Character java/lang/Double java/lang/Exception java/lang/Integer java/lang/Math java/lang/Runnable java/lang/String java/lang/StringBuffer java/lang/System java/lang/Thread java/util/Calendar java/util/GregorianCalendar length loading glyphs... mythread Oname extension to be used with image ( i.e '.gif' , '.jpg' - defaults to '.gif' out paint point preWarp precision println radix repaint run
showStatus sleep stardate
stardate.java start stop substring toString update valueOf warpStart width yearFractionMultiplyer yearFractionPadder
yearPrecision ! 0   )   ç  ð   
æ  ð   > ã  ð    é  ð    é  ð    ã  ð   L ã  ð   ÿ é  ð   û é  ð   ; ÷  ð   6 ê  ð    ø  ð  : ç  ð  Ý ç  ð  M ä  ð  # N ä  ð  #  ä  ð  $  ä  ð  $ < ã  ð  & O ã  ð  (  ã  ð  *  ï ã  ß   ð  0 K ë  ð  7  Â  Þ ,   Ì**¶ L¸ l¶ Uµ `§ L² Y+¶ ^² Y ¶ _*
µ `*´ `? *
µ `**¶ L¸ l¶ Uµ ]§ L² Y+¶ ^² Y ¶ _*µ ]*´ ] *µ ]**¶ L¸ l¶ Uµ r§ L² Y+¶ ^² Y
¶ _*µ r*´ ] *µ r**¶ Lµ R*´ RÇ 0*» *Y· 6µ R§ L² Y+¶ ^² Y¶ _*» *Y· 6µ R*´ RÇ *» *Y· 6µ R**¶ Lµ S*´ SÇ 0*» *Y· 6µ S§ L² Y+¶ ^² Y¶ _*» *Y· 6µ S*´ SÇ *» *Y· 6µ S*
µ p*µ Q§ *Y´ p*´ `?iµ p*Y´ Q`µ Q*´ Q*´ r¡ÿà**´ `?*´ piµ q*
µ C*µ Q§ *Y´ C*´ `?iµ C*Y´ Q`µ Q*´ Q*´ ]¡ÿà**´ C*´ `?iµ D*¶ b***¶ I» +Y*´ R¸ k· 7¶ ;*´ S¶ ;¶ h¶ Kµ [² Y» +Y*´ R¸ k· 7¶ ;*´ S¶ ;¶ h¶ _***¶ I» +Y*´ R¸ k· 7¶ ;*´ S¶ ;¶ h¶ Kµ 8**´ `½ !µ N*µ Q§ @*´ N*´ Q**¶ I» +Y*´ R¸ k· 7*´ Q¸ i¶ ;*´ S¶ ;¶ h¶ KS*Y´ Q`µ Q*´ Q*´ `¡ÿ»**¶ >´ nµ o**¶ >´ Oµ P***´ o*´ P¶ Bµ ?**´ ?¶ Jµ F*¶ b±    & 6 F I & j z } & ? ¼ ¿ & ð &  å & I > ?  >  A  B  C # D ) F 0 G 6 J 6 K F J I M J N Q O Y P ^ R e S j U j V z U } X ~ Y ? Z [ ? ] ? ^ ? a ? b ¨ c ¯ d ¼ a ¿ f À g Ç h Ï i Ü l ã m ð q ð r ú s t q v w x! y. |5 }B ?G ?O ?] ?r ?? ??  ?? ° ¾ ?Ä ?í ? ?9 ?D ?L  ?? ¡? ¢ª ¤º ¥Å §Ë ¨ ð  9  À  Þ "  
» *Y· 6°  å   « ð  ª  Ã  Þ ¹   u½ Y½ *YSYSYSSY½ *YSYSYSSY½ *YSYSYSSY½ *YSY
SYSSY½ *YSY
SYSSL+°  å 2 ¯  °  ¯  ± / ¯ 2 ² E ¯ H ³ [ ¯ ^ ´ q ¯ s ¶ ð  ® 9 Î  Þ    È*¶ A*´ F*´ 8*¶ GW6=§ 7*´ =¶ @*´ `¸ E>*´ F*´ N2*¶ GW*´ N2*¶ M`6?*´ =¶ W¡ÿÄ*´ F*´ [*¶ GW*´ [*¶ M`6=§ 7*´ :¶ @*´ `¸ E>*´ F*´ N2*¶ GW*´ N2*¶ M`6?*´ :¶ W¡ÿÄ+*´ ?*¶ GW±  å F  »  Â  Å  Æ  Ç + È = É L Æ Z Ë j Ì w Î | Ï ? Ð ? Ñ ­ Î » Ø Ç Ú ð  ¸ I Î  Þ "   *+¶ Z±  å
 Ý  Þ ð  Ü  Â  Þ ?    » /Y· 2:¶ H*´ m¶ Hd<*´ m¶ <?
*µ \¸ 9<¶ H¶ V? ¶ Hd? yo9§ ¶ Hd? wo9 ¶ H? {k ¶ H? ukc
¶ H?c }oI*» +Y*´ `¸ j¸ k· 7» %Y*´ p?k*´ q?c· 3¶ T*´ `¸ j¶ f¶ ;¶ hµ =*» %Y*´ C?(k*´ D?c· 3¶ T*´ `¸ j¶ fµ :*´ :¶ W*´ ]¤ **´ :*´ ]¶ gµ :±  å z  ç é  ë % ì * í / ñ = ò M ñ P õ ` ÷ l ø x ÷ y ù ? ø ? ù ? ÷ ? ÿ ? À ÿ Æ Ò
Ö Û
Þ â å é ì ú

 ð  ä E Â  Þ I   !* ¶ b*» -Y*· 5µ X*´ XÆ
*´ X¶ d±  å        ð  @ Â  Þ E   *¶ a s¸ c§ÿöW§ÿò  

&  å    ! "
!
# ! ð  F Â  Þ B   *¶ b*´ XÆ *´ X¶ e*µ X±  å   ) *
+ , . ð '  Â  Þ #   *¶ b±  å
 1 2 ð 0  Û Â  Þ :   *· 1*µ \*» /Y · 4µ m±  å      7 ð    ñ D ð  
</body>

That's the .class file that I put in the <body> </body> tags. Someone please help me. I'm going out of my mind. There has to be an easier way. *Sighs*

(Edited by Mr_Wizard on 05-05-2007 22:39)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 05-05-2007 22:46 Edit Quote

You have no clue about what you're doing, do you ?

Read Tyberius Prime's post again. What you have here is Java, NOT JavaScript. To embed a Java applet into a web page, you have to use the OBJECT tag and make it point to your .JAR file. But using Java for a clock is really overdoing it. JavaScript can do the job with far less hassle.

Just google for Java applet, and check the markup of pages including Java applets to see how it's done. Have a look at Is the &lt;APPLET> tag being phased out? as well.

If you want to go JavaScript, check the thread I posted above, try to write a script and don't hesitate to ask if you need help on a specific topic.



(Edited by poi on 05-06-2007 02:01)

Mr_Wizard
Nervous Wreck (II) Inmate

From: OZONE Asylum
Insane since: Apr 2007

IP logged posted posted 05-06-2007 03:28 Edit Quote

No I don't. I need *serious* help here. If you would be so kind please, as to give me the code, (I tryed the one you posted here I got a script error) I would be gratefull.

The Wizard of Atari-Sega-Nendo-Photoshop, admitted for making too many photo shop projects.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 05-06-2007 03:59 Edit Quote

hum, I didn't post any code sample in this thread.

However having a look at the entries of the 20 lines JS - Roman clock contest and google'ing for JavaScript clock should already give you quite a few hints to make your own clock.

I suggest you to have a look at the Javascript/DHTML. Starting with only the first 3 links should give you all you the infos you need to get started with JS and more.

Last but not least, when report problems it helps a lot to provide a link to your work in progress so people can see the whole thing live.

Mr_Wizard
Nervous Wreck (II) Inmate

From: OZONE Asylum
Insane since: Apr 2007

IP logged posted posted 05-07-2007 01:54 Edit Quote

After spending 3 hours on Google, I found zip that would help. I looked at the 3 links you advised but did not understand a lot of it. I did not provide a link because I wont upload it untill it's done. All I get is the actual code showing. I upload all the images into a temp directory and link it all to a webpage thats on a random site for testing, run from work. No one would see it untill it's completed and moved to it's new home. Youu would get a 404 dissalowing page.

The Wizard of Atari-Sega-Nendo-Photoshop, admitted for making too many photo shop projects.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 05-07-2007 16:18 Edit Quote

there is no '404 disallowing' page. 404 means document not found.
403 would be 'access forbidden'...

Honestly, though the water's not that deep in this pond, people have drowned in a puddle. If you're worknig with a zip you 'found on Google' at least make sure it's got a licence that suits your needs - less the author get's your site shut down for copyright violations...

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 05-07-2007 19:07 Edit Quote

3 hours on Google, a submarine project no one can see, random site for testing, a 404 dissalowing page.

Man, I didn't know Trekkie clock was such serious business.

Oh well. At least we tried to help you.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 05-07-2007 20:14 Edit Quote

but captain, the future of earth depends on it!

SCNR

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

IP logged posted posted 05-07-2007 20:20 Edit Quote

here is a tutorial that shows how to set up a stardate using a java applet.

http://javaboutique.internet.com/stardate/



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu