*
The moose likes Java Micro Edition 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
JavaRanch » Java Forums » Mobile » Java Micro Edition
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();
}
}
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
You will probably get better assistance with this in the Applets forum. I will move it there for you.


Matthew Phillips
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do you create an java alarm clock with audio?