OZONE Asylum
Forums
DHTML/Javascript
Javascript Stardate Clock
This page's ID:
29187
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
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"); } } [/code] 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. [small](Edited by [url=http://www.ozoneasylum.com/user/1424]Tyberius Prime[/url] on 05-05-2007 13:40)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »