Results 1 to 11 of 11
  1. #1
    Required is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Clock that beeps every 15 30 45 00

    Hello,

    I am a (very) novice Java programmer. I have set myself a project to write a timer that beeps every quarter, half and quarter and top of the hour.

    I used to use something called naked alarm clock, but now they seem to have shut down.

    Can anyone help me?

    (I am on page 56 in Barry Burd's java for dummies!)

    Thank you for any input.

  2. #2
    Required is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Clock that beeps every 15 30 45 00

    I know it will be something along the lines of

    if (System.currentTimeMillis() = 15 | 30 | 45 |) { }

    Am I on the right track?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Clock that beeps every 15 30 45 00

    You should read the API doc for any class and method you want to use.
    Several problems with this code: if (System.currentTimeMillis() = 15 | 30 | 45 |) {
    1)The method does not return seconds. Read the API doc to see what it returns
    2) the = operator is for assigning values. The == operator is for comparing the values of operands
    3) The | operator ORs together two operands and returns an int value The || operator connects two boolean expressions into a single boolean value.
    4) To compare one operand to several values, there must be a separate expression for each comparison. There is no shortcut: (a < b) || (a < c) || (a < d)
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Required is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Clock that beeps every 15 30 45 00

    Yikes

    See, there is no timer like this on the net. I have searched till my eyes, uh, fingers bled!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Clock that beeps every 15 30 45 00

    Maybe you want to contact a 'time of day' server; e.g. 128.138.141.172 on port 13 returns a time String each time you read from it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Required is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Clock that beeps every 15 30 45 00

    Yes I will contact a time of day server.

    But first I will need my Ph.D in Software Engineering.

    I was told that Java is a "working man's" language that I can easily use.

    Guess I was wrong.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Clock that beeps every 15 30 45 00

    Yes, Java is not that easy. It has a lot of strict rules that you need to follow.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Clock that beeps every 15 30 45 00

    Quote Originally Posted by Required View Post
    I was told that Java is a "working man's" language that I can easily use.

    Guess I was wrong.
    Not many (any?) languages will let the programmer just make up syntax and expect it to work.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Clock that beeps every 15 30 45 00

    Quote Originally Posted by Required View Post
    Yes I will contact a time of day server.

    But first I will need my Ph.D in Software Engineering.

    I was told that Java is a "working man's" language that I can easily use.

    Guess I was wrong.
    Even telnet can do it:

    Java Code:
    telnet 128.138.141.172 13
    And telnet is braincell challenged ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Required is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Clock that beeps every 15 30 45 00

    Right

    I got this program:

    // File: textclock/Clock.java
    // Description: This implements a text clock by subclassing
    // JTextField, changing its appearance and
    // adding a timer to update itself.
    // Regarding subclassing JTextField
    // PROS: It's simple.
    // All JTextField methods are available
    // to the user, so they can easily
    // customize it (fonts, colors, ...);
    // CONS: It can't become more complicated, eg,
    // to add buttons, etc. because the
    // users may already be using the
    // JTextField methods.
    // Author: Fred Swartz,
    // Date: 15 Feb 2005
    // Possible Enhancements:
    // Appearance: center, leading zeros, uneditable,
    // Function: 12/24 hour, alarm, timer, stop and start.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Calendar;

    ///////////////////////////////////////////////////////////// Clock
    class Clock extends JTextField {
    javax.swing.Timer m_t;

    //================================================== constructor
    public Clock() {
    //... Set some attributes.
    setColumns(6);
    setFont(new Font("sansserif", Font.PLAIN, 48));

    //... Create a 1-second timer.
    m_t = new javax.swing.Timer(1000, new ClockTickAction());
    m_t.start(); // Start the timer
    }

    /////////////////////////////////////////// inner class listener
    private class ClockTickAction implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    //... Get the current time.
    Calendar now = Calendar.getInstance();
    int h = now.get(Calendar.HOUR_OF_DAY);
    int m = now.get(Calendar.MINUTE);
    int s = now.get(Calendar.SECOND);
    setText("" + h + ":" + m + ":" + s);
    }
    }
    }

    So I will set an if statement just after setText and now I need to know how to make an audio object to call to play a short wav file.

    Am I correct?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Clock that beeps every 15 30 45 00

    Try it and see what happens.
    If you don't understand my response, don't ignore it, ask a question.

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, 10:10 AM
  2. Replies: 5
    Last Post: 06-27-2012, 10:52 PM
  3. Easiest way to detect beeps in audio file
    By bill17 in forum New To Java
    Replies: 0
    Last Post: 11-26-2011, 04:46 PM
  4. help with clock
    By Bimz in forum New To Java
    Replies: 1
    Last Post: 09-26-2011, 01:50 PM
  5. clock
    By ws6driver in forum New To Java
    Replies: 1
    Last Post: 07-31-2009, 04:15 AM

Posting Permissions

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