Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   (Not GScript) A simple clock (https://forums.graalonline.com/forums/showthread.php?t=72615)

godofwarares 03-05-2007 04:28 PM

(Not GScript) A simple clock
 
I made this out of pure free time. It's Java so it won't work on Graal -- Sorry guys. You might be able to get some good ideas / good formulas off of this however.

Alert: This is an applet. You can use it on a webpage by compiling it and using this code:
HTML Code:

<APPLET CODE=Clock.class WIDTH=100 HEIGHT=100>
</APPLET>


PHP Code:

public class Clock extends javax.swing.JApplet
{
    public 
int clockX;
    public 
int clockY;
    public 
int clockW;
    public 
int clockR;
    public 
double sa;
    public 
double sda;
    public 
double mda;
    public 
double hda;
    public 
int sr;
    public 
int mr;
    public 
int hr;
    public 
int s;
    public 
int m;
    public 
int h;
    public 
int secondX;
    public 
int secondY;
    public 
int minuteX;
    public 
int minuteY;
    public 
int hourX;
    public 
int hourY;
    
    public 
void init()
    {
        
// Start the timer; Variables here don't matter
        // since they're in the Paint method.
        
        
javax.swing.Timer clock = new javax.swing.Timer(500updateClock);
        
clock.start();
    }
    
    public 
void paint(java.awt.Graphics g)
    {
        
clockX = (getWidth()/2);
        
clockY = (getHeight()/2);
        
        
clockW = (getWidth()-1);
        
clockR = ((getWidth()-1) / 2);
        
        
sa = (Math.PI 2);
        
sda = (Math.PI 30);
        
mda = (Math.PI 30);
        
hda = (Math.PI 6);
        
        
sr clockR;
        
mr = (int) (0.9 clockR);
        
hr = (int) (0.7 clockR);
        
        
g.fillRect(00getWidth(), getHeight());
        
g.setColor(new java.awt.Color(255255255));
        
        
java.util.Date d = new java.util.Date();
        
        
d.getSeconds();
        
d.getMinutes();
        
d.getHours();
        
        
secondX = (int) ((getWidth() / 2) + Math.cos((sda) - sa) * sr);
        
secondY = (int) ((getWidth() / 2) + Math.sin((sda) - sa) * sr);
        
        
minuteX = (int) ((getWidth() / 2) + Math.cos((mda) - sa) * mr);
        
minuteY = (int) ((getWidth() / 2) + Math.sin((mda) - sa) * mr);
        
        
hourX = (int) ((getWidth() / 2) + Math.cos((hda) - sa) * hr);
        
hourY = (int) ((getWidth() / 2) + Math.sin((hda) - sa) * hr);
        
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), secondXsecondY );
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), minuteXminuteY );
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), hourXhourY );
        
        
g.drawOval(00, (getWidth()-1), getHeight()-1);
        
        
String stime = (12 ":" + (10 "0" m) + ":" + (10 "0" s) + " " + (11 "PM" "AM"));
        
showStatus("The time is now: " stime ".");
    }
    
    
java.awt.event.ActionListener updateClock = new java.awt.event.ActionListener()
    {
        public 
void actionPerformed(java.awt.event.ActionEvent evt)
        {
            
repaint();
        }
    };


Just in case nobody has compilers, Forum PM me and i'll give you the class file.

Enjoy.



Note: I KNOW THIS ISN'T A JAVA FORUM.
I just thought it would help someone >_>

Zeta0 03-05-2007 04:32 PM

gk hik repped

Skyld 03-05-2007 05:58 PM

I'll let the thread stay since the formulae might help some people, but ideally you shouldn't post code in different languages here.

godofwarares 03-05-2007 07:09 PM

Alright


All times are GMT +2. The time now is 04:18 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.