This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Reply locked New topic
Author

How to 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();
}
}
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

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


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create an Java Alarm clock with audio?
 
Similar Threads
How do you create an java alarm clock with audio??
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?
Java ScrollBanner