Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help need for Java alarm clock please

  Asked By: Bogart    Date: Jun 08    Category: Java    Views: 2288
  

I need to create an alarm clock, that would sound at a right time
when users compare the clock and type the exact interger within the
edit box... However, I couldn't get the clock showing...so what can I
do?? Please help!!

Here is the codes:

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();
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Help need for Java alarm clock please Or get search suggestion and latest updates.




Tagged: