This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Applets and the fly likes How to create an Java Alarm clock with audio? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Reply locked New topic

How to create an Java Alarm clock with audio?

John Wong

Joined: May 06, 2003
Posts: 4
Hi guys,
This is my first time here in this form...hope you guys and gals can help!!
How do you create an Java alarm clock with audio that will sound at a correct time??
I basically created 2 edit box, and when I typed the exact interger, the label will say "interger match!"...however, I would also like to show the clock within the applet, so how do you do it???
here is the java code I wrote earlier...hope you all can point out or give me some idea of how to do it....
import java.awt.*;
import java.applet.*;
import java.awt.Graphics;
import java.util.Date;
import javax.swing.Timer;
public class j27 extends Applet {
AudioClip audClip;
String Msg1=null;
String Msg2=null;
Label info;
TextField box1Text;
TextField box2Text;
Checkbox charTrue;
int myVar1=0, myVar2=1;
Font theFont=new Font("TimesRoman", Font.BOLD, 24); //
Date theDate; //
Thread runner; //

public class Rebound extends Applet
private Timer timer;}

public void init() {
info = new Label ("string and integer demo");
add (info);
box1Text=new TextField("12");
add (box1Text);
box2Text=new TextField("34");
add (box2Text);
Button load=new Button("process");
add (load);
charTrue=new Checkbox ("treat input as text");
add (charTrue);

timer = new Timer (DELAY, new ReboundMouseMouseListener());
public boolean action (Event event, Object object) {
if( instanceof Button) {
if (charTrue.getState() !=true) { //test for text or integer input
myVar1 = Integer.parseInt (Msg1); //if integer input convert string
myVar2 = Integer.parseInt (Msg2); }
repaint(); }
public void start()
if (runner == null)
runner = new Thread (this); //new thread
public void stop() {
if(runner!=null) {
runner.stop(); //kill thread
runner = null; }}
public void run()
theDate = new Date();
try {Thread.sleep(1000);} //thread sleeping 1 second
catch (InterruptedException e) {}
public void paint (Graphics g) {

if (Msg1 !=null) g.drawString( "box1=" + Msg1, 30, 140);
if (Msg2 !=null) g.drawString( "box2=" + Msg2, 30, 150);
if (charTrue.getState()==true) { //text for text or string
if (Msg1.compareTo(Msg2)==0) g.drawString ("strings match!", 30, 160); }
if (myVar1 == myVar2) g.drawString ("integers match!", 30, 170);
audClip = getAudioClip(getCodeBase(),"");
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17276

This posting is a duplicate, so it's being closed in order to avoid confusion.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to create an Java Alarm clock with audio?
jQuery in Action, 3rd edition