Java Micro Project
Java Micro Project
******************Stop Watch******************
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Panel p;
Label display;
//Button
//Time
String disp;
boolean on;
//Initialization
public void init()
on=false;
hour=minute=second=millisecond=0;
//Label
disp="00:00:00:000";
display.setText(disp);
p.add(display);
start.addActionListener((ActionListener)this);
p.add(start);
reset.addActionListener((ActionListener)this);
p.add(reset);
stop.addActionListener((ActionListener)this);
p.add(stop);
add(p);
//Reset Function
try{
Thread.sleep(1);
}
System.out.println(e);
}
hour=minute=second=millisecond=0;
}
//Update function
millisecond++;
if(millisecond==1000) {
millisecond=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
}
}
//Changing Label
if(hour<10)
else
if(minute<10)
else
if(second<10)
else
if(millisecond<10)
disp+="00"+millisecond;
else if (millisecond<100)
disp+="0"+millisecond;
else
disp+=millisecond;
display.setText(disp);
}
//thread.run function
while(on)
try{
Thread.sleep(1);
update();
//changeLabel
changeLabel();
catch(InterruptedException e){
System.out.println(e);
}
//actionPerformed
//To listen to the actions on the buttons
if(e.getSource()==start)
//stopwatch is on
on=true;
//reset
if(e.getSource()==reset)
//stopwatch off
on=false;
reset();
changeLabel();
if(e.getSource()==stop)
//stopwatch off
on=false;}
**********************Applet Code*********************
<html>
<body>
<applet>
</applet>
</body>
</html>
Conclusion:-
Hence from this project we successfully learn to develop a stop watch using applet by
using Action Listener to handle events. This program contains three buttons Start , Stop and
Reset. When the Start button is placed the timer gets start , when we press the Stop button the
the timer gets stop and when the Reset button is pressed then the timer again starts from its
initial value.