0% found this document useful (0 votes)
11 views16 pages

Aarti

The document outlines a micro-project aimed at designing a stopwatch using Java applets, focusing on developing skills in Java programming, interfaces, and Action Listener implementation. It details the methodology, program structure, and code for creating a functional stopwatch with start, stop, and reset capabilities. The project concludes with a successful demonstration of the stopwatch functionality and event handling through button interactions.

Uploaded by

sycob9275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

Aarti

The document outlines a micro-project aimed at designing a stopwatch using Java applets, focusing on developing skills in Java programming, interfaces, and Action Listener implementation. It details the methodology, program structure, and code for creating a functional stopwatch with start, stop, and reset capabilities. The project concludes with a successful demonstration of the stopwatch functionality and event handling through button interactions.

Uploaded by

sycob9275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Stop Watch designing using Applet

Aims/Benefits of the micro-project

The aim of the course is to help the student to affiant following industry identify compendance through
various teaching, learning experience.

Course outcome addressed.

 Develop a program using applet in java.


 Apply the concept of interface in the program
 Develop a program using Action Listener in java.

Proposed methodology

Java uses statements of control the flow of execution of program based on certain conditions. This are used
to cause the flow of execution to book conditions. Person will able to use switch case to check multiple
conditions.
Introduction:-

Java is object-oriented, cross platform, multi-purpose artificial language created by Sun


Microsystem. 1st free in 1955, it had been developed to be a machine freelance net technology.
it had been supported C and C++ syntax to create it straightforward for programmers from those
communities to be told. Since then, it had been attained a distinguished place within the world of
programing. Java has several characteristics that have contributed to its popularity:

Platform freelance – several languages area unit compatible with only 1 platform. Java was
specifically designed in order that it might run on any laptop, regardless if it had been running
Windows, Linux, Mac, UNIX operating system or any of the opposite software package.

Simple and simple to use – Java’s creators tried to style it therefore code can be written with
efficiency and simply. Java doesn't have some drawbacks. Since it's automatic trash collection, it
will tend to use additional memory than alternative similar languages. There area unit typically
implementation variations on completely different platforms, that have LED to Java being
delineated as a “write once, check everywhere” system. Lastly, since it uses associate degree
abstract “virtual machine”, a generic java program doesn’t have access to native API’s on a
system directly.
What is Applet?

An applications programme is dynamic and interactive java program that run within the net
page or applets are tiny java programs that are primarily utilized in net computing. The java
application programs run on prompt exploitation java interpreter whereas the java applets will be
transported over the web from one laptop to a different and run exploitation the Applet viewer or
any application program that support java. AN applications programme is like program which
may perform arithmetic operations, show graphic, play sounds settle for user input, produce
animation and play interactive games. To run AN applications programme, it should be enclosed
in hypertext makeup language tags for online page. application program may be a program to
look at online page. Java has enabled sites to make and use absolutely hypermedia system net
documents. An internet page will currently contain not solely a straightforward text or a static
image however additionally a Java applications programme that, when run, will manufacture
graphics, sounds and moving pictures. this java applications programme has created vital impact
on World Wide net. AN applications programme category extends from AWT Panel category, that
extend AWT instrumentation category, that extend AWT part category. AN applications
programme is largely a specialised panel that's embedded in an exceedingly.
Specialized element instrumentality referred to as applications programme Context which might
be an online browser to show associate applications programme. From element category
associate applications programme inherits the flexibility to draw and handle event. From
instrumentality, associate applications programme inherits the flexibility to incorporate alternative
elements and to own layout manager to manage the dimensions and position of these elements.
associate applications programme implements no. of strategies that the applications programme
context calls once it need to initialize, start, stop or destroy the applications programme.
Following program shows the chain of categories genetic by applications programme
category in java:

java.lang.Object

java.awt.Component

java.awt.Container

java.awt.Panel

java.applet.Applet
Program Information:-

1. once the beginning button is click, we tend to begin the timer. whereas the reset or stop button
isn’t pressed the we tend to keep the timer running i.e we alter the worth of the timer
(HH:MM:SS:MS) each one time unit so update the screen.

2. once button is clicked, then we have a tendency to stop the timer and set it to its default worth
(00:00:00:000). 3. once the stop button is ironed, then we have a tendency to stop the timer with
the worth because it is. 4. once the beginning button is ironed and if no alternative button is
placed the timer can continue and can stop only if the applications programme program is
closed.

Procedure:-

a) Importing all the specified packages within the program.

b) Declare a category that extends application and implements Runnable .Action Listener.

c) Develop a Panel to stay all the buttons and labels

d) Initialize all the specified variables of kind Button, int, String and mathematician

e) Declare a user-defined technique to initialize all the variables that are to be used

f) Then declare a performs to reset () the timer that contain the try-catch block to handle
exception.

g) Then declare the perform update () to line all the values consequently.

h) Develop a change Label () methodology to properly format the show of the timer in output.

i) Then develop a run () methodology to handle the activation of timer

j) Then develop an Action Listener () to handle the button click event properly.
Program Code:-

******************Stop Watch******************

import java.applet.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class Clock extends Applet implements Runnable,ActionListener

//Panel to keep all the buttons and label

Panel p;

Label display;

//Button

Button start, stop, reset;

//Time

int hour, minute,second,millisecond;

//String to be displayed on the label

String disp;

//State of stopwatch on/off

boolean on;

//Initialization
public void init()

//Initially off

on=false;

p=new Panel();

//Setting layout of the panel

p.setLayout(new GridLayout(4,1,6,10));

//Initial time 00:00:00:000

hour=minute=second=millisecond=0;

//Label

display =new Label();

disp="00:00:00:000";

display.setText(disp);

p.add(display);

//Start Button

start=new Button("Start");

start.addActionListener((ActionListener)this);

p.add(start);

//Reset Button

reset = new Button("Reset");

reset.addActionListener((ActionListener)this);

p.add(reset);
//Stop Button

stop=new Button("Stop");

stop.addActionListener((ActionListener)this);

p.add(stop);

add(p);

//Starting Thread

new Thread(this,"StopWatch").start();

//Reset Function

//Reset to default value

public void reset()

try{

Thread.sleep(1);

catch(Exception e){

System.out.println(e);

hour=minute=second=millisecond=0;

//Update function

//Update the timer


public void update()

millisecond++;

if(millisecond==1000) {

millisecond=0;

second++;

if(second==60)

second=0;

minute++;

if(minute==60)

minute=0;

hour++;

//Changing Label

public void changeLabel()

//Properly formatting the display of the timer

if(hour<10)
disp="0"+hour+" : ";

else

disp=hour+" : ";

if(minute<10)

disp+="0"+minute+" : ";

else

disp+=minute+" : ";

if(second<10)

disp+="0"+second+" : ";

else

disp+=second+" : ";

if(millisecond<10)

disp+="00"+millisecond;

else if (millisecond<100)

disp+="0"+millisecond;

else

disp+=millisecond;

display.setText(disp);

//thread.run function

public void run()

{
//while the strength is on

while(on)

try{

//pause 1 millisecond

Thread.sleep(1);

//update the timer

update();

//changeLabel

changeLabel();

catch(InterruptedException e){

System.out.println(e);

//actionPerformed

//To listen to the actions on the buttons

public void actionPerformed(ActionEvent e)

//start a thread when start button is clicked

if(e.getSource()==start)
{

//stopwatch is on

on=true;

new Thread(this,"StopWatch").start();

//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 code=”Clock.java” width=400 height=600>

</applet>

</body>

</html>
Output:-
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
timer gets stop and when the Reset button is pressed then the timer again starts from its initial
value.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy