Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes How do you 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do you create an java alarm clock with audio??" Watch "How do you create an java alarm clock with audio??" New topic
Author

How do you create an java alarm clock with audio??

John Wong
Greenhorn

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....
Thanks!!
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 j27.java");
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());
timer.start();
}
public boolean action (Event event, Object object) {
if(event.target instanceof Button) {
Msg1=box1Text.getText();
Msg2=box2Text.getText();
if (charTrue.getState() !=true) { //test for text or integer input
myVar1 = Integer.parseInt (Msg1); //if integer input convert string
myVar2 = Integer.parseInt (Msg2); }
repaint(); }
return(true);
}
public void start()
{
if (runner == null)
{
runner = new Thread (this); //new thread
runner.start();
}
}
public void stop() {
if(runner!=null) {
runner.stop(); //kill thread
runner = null; }}
public void run()
{
while(true)
{
theDate = new Date();
repaint();
try {Thread.sleep(1000);} //thread sleeping 1 second
catch (InterruptedException e) {}
}
}
public void paint (Graphics g) {
g.setFont(theFont);
g.drawString(theDate.toString(),10,50);
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); }
else
if (myVar1 == myVar2) g.drawString ("integers match!", 30, 170);
else
audClip = getAudioClip(getCodeBase(),"loop.au");
audClip.loop();
}
}

Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
The creation of the alarm clock will be left as an exercise to the original poster, but here are some tips...
- Look at Java's Timer classes.
- You can just display chars/String to some GUI display to create a digital clock. If you can an analog one, you need some type of circle or cirular guage widget.
- A google search will probably turn up some useful code.
--Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you create an java alarm clock with audio??
 
Similar Threads
how to add button to this?
how do you create an java alarm clock with audio?
how do you create an java alarm clock with audio?
How to create an Java Alarm clock with audio?
Java ScrollBanner