Results 1 to 10 of 10

Thread: Clock JavaBean

  1. #1
    dns.gonz is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Smile Clock JavaBean

    I just created a clock javabean based on the Windows gadget created by George Harrison VAtch by `GeorgeHarrison on deviantART.

    You can get the library (with a test jar) here:

    Download myclock.zip from Sendspace.com - send big files the easy way

    Let me know if you like it. :D

  2. #2
    Mefisto is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default

    Hi, I like your clock it's very cool!

  3. #3
    dns.gonz is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Cool New skins

    Great you liked it man...

    This one I'm sending here has some other skins.

    MyClock.jar
    Last edited by dns.gonz; 05-10-2010 at 04:20 AM.

  4. #4
    Eimo is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default Clock

    Hi,
    I've tried to see your clock, but It's not loading in the bean box??

    anu suggestions?

  5. #5
    dns.gonz is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default Suggestion

    I suggest using Netbeans...

    I'm sending a test netbeans (6.9.1) project...

    If you have any other questions let me know =)

    Test Project

  6. #6
    Eimo is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default

    Thank you so much for reply, that looks so cool.

    However, I wanted to ask you about javabean, because I'm doing digital/analog clock bean program. and I think I'm having a problem with the run() method because nothing is displayed at all in the bean box :(

    I think I'm having a problem with the thread, don't know should I send you the code and see what's the problem!!!!

  7. #7
    dns.gonz is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default Netbeans javaBeans tutorial

    This is a good place to start.

    Tutorial

  8. #8
    Eimo is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default

    Ok, that's my initial code in the program, I couldn't go far because basically I cannot see any output. At least the digital clock part :( I hope you can help me.

    //Imports
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import java.io.Serializable;
    import java.util.Calendar;

    public class Clock extends Canvas implements Serializable, Runnable {

    // state & properties
    private transient Image offImage;
    private transient Graphics offGrfx;
    private transient Thread clockThread = null;
    private transient Dimension offSize;
    private boolean raised;
    private boolean digital;

    // Constructors
    public Clock() {
    this(false, false);
    }

    public Clock(boolean r, boolean d) {
    // Allow the superclass constructor to do its thing
    super();

    // Set properties
    raised = r;
    digital = d;

    // set Background
    setBackground (Color.lightGray);

    //set default size
    setSize(120,80);

    //create and start the clock thread
    clockThread = new Thread();
    clockThread.start();
    }

    // Accessor methods
    public boolean isRaised() {
    return raised;
    }

    public void setRaised(boolean r) {
    raised = r;
    repaint();
    }

    public boolean isDigital() {
    return digital;
    }

    public void setDigital(boolean d) {
    digital = d;
    repaint();
    }

    // Other public methods
    public void run() {
    try {
    while (true) {
    repaint();
    }
    //delay for one second
    clockThread.currentThread().sleep(1000);
    } catch (InterruptedException e) {}
    }
    clockThread.start();
    }

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

    public synchronized void paint(Graphics g) {
    Dimension d = getSize();

    // Create the offscreen graphics context
    if (offGrfx == null || (offSize.width != d.width) ||
    (offSize.height != d.height)) {
    offSize = d;
    offImage = createImage(d.width, d.height);
    offGrfx = offImage.getGraphics();
    }

    // Paint the background with 3D effects
    offGrfx.setColor(getBackground());
    offGrfx.fillRect(1, 1, d.width - 2, d.height - 2);
    offGrfx.draw3DRect(0, 0, d.width - 1, d.height - 1, raised);
    offGrfx.setColor(getForeground());

    // Paint the clock
    if (digital)
    drawDigitalClock(offGrfx);
    else
    drawAnalogClock(offGrfx);

    // Paint the image onto the screen
    g.drawImage(offImage, 0, 0, null);
    }

    // Private support methods
    private void drawAnalogClock (Graphics g) {

    Dimension d = getSize();
    g.setFont(getFont());

    int Radius = d.width/2;
    Point center = new Point (d.width/2, d.height/2);

    // Draw the clock shape
    g.setColor(Color.white);
    g.fillArc(center.x, center.y, d.width, d.height, 0, 360);
    //g.setColor(Color.black);
    //g.drawArc(center.x, center.y, d.width, d.height, 0, 360);

    // Draw the hour hand

    // Draw the minute hand

    //Draw the second hand and center

    }

    private void drawDigitalClock(Graphics g) {

    Dimension d = getSize();

    // Get the time as a string
    Calendar now = Calendar.getInstance();
    String Time = now.get(Calendar.HOUR) + ":" +
    now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND);

    // Draw the time
    g.drawString(Time, d.height, d.width);

    }
    }


    ========================

    If you please can advice me I would be appreciate it.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  10. #10
    Eimo is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default Hand, minutes, and seconds hadles

    May I ask how can I draw the handles and numbers in a clock. I found out how to do the hour handle:

    Point center = new Point(getWidth()/2, getHeight/2);
    int scale = Math.round(getWidth()/2.5);
    Point hand = hoursToLocation(hours, center, scale);
    g.setColor(Color.black);
    g.drawLine(center.x, center.y, hand.x, hand.y);

    But how can I calculate the minutes and seconds and how it will swing???

Similar Threads

  1. 24 hour clock to 12 hour clock project.
    By bs3ac in forum New To Java
    Replies: 4
    Last Post: 01-08-2013, 11:10 AM
  2. JavaBean
    By hannes in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 08:51 PM
  3. components in javabean
    By NAIYYAR ALI in forum Advanced Java
    Replies: 0
    Last Post: 10-05-2009, 04:36 PM
  4. Enterprise JavaBean 3.0
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 06-20-2008, 12:42 AM
  5. JavaBean Problem
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-05-2007, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •