Results 1 to 11 of 11
- 09-15-2012, 08:21 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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.
- 09-15-2012, 08:28 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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?
- 09-15-2012, 08:52 PM #3
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.
- 09-15-2012, 09:01 PM #4
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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!
- 09-15-2012, 09:09 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-15-2012, 09:17 PM #6
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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.
- 09-15-2012, 09:23 PM #7
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.
-
Re: Clock that beeps every 15 30 45 00
- 09-15-2012, 09:37 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
- 09-15-2012, 11:10 PM #10
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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?
- 09-16-2012, 01:01 AM #11
Similar Threads
-
24 hour clock to 12 hour clock project.
By bs3ac in forum New To JavaReplies: 4Last Post: 01-08-2013, 10:10 AM -
Trying to create a program that beeps after a user-specified interval using a gui
By merrymac in forum New To JavaReplies: 5Last Post: 06-27-2012, 10:52 PM -
Easiest way to detect beeps in audio file
By bill17 in forum New To JavaReplies: 0Last Post: 11-26-2011, 04:46 PM -
help with clock
By Bimz in forum New To JavaReplies: 1Last Post: 09-26-2011, 01:50 PM -
clock
By ws6driver in forum New To JavaReplies: 1Last Post: 07-31-2009, 04:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks