Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create an Java Alarm clock with audio?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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();
}
}
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This posting is a duplicate, so it's being closed in order to avoid confusion.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic