Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an applet that simulates a stopwatch. It should have a Start button and a

ID: 3885051 • Letter: W

Question

Write an applet that simulates a stopwatch. It should have a Start button and a Stop button. When the Start button is clicked the applet should count the seconds that pass. When the Stop button is clicked, the applet should stop counting seconds.

This is what I have and it works fine, BUT my teacher said we need to upload the Stopwatch.java file AND the Stopwatch.html file...I'm not sure how to make the html file? Can someone help?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class Stopwatch extends JFrame implements ActionListener, Runnable
{
private long startTime;
private final static java.text.SimpleDateFormat timerFormat = new java.text.SimpleDateFormat("mm : ss.SSS");
private final JButton startStopButton= new JButton("Start/stop");
private Thread updater;
private boolean isRunning= false;
private final Runnable displayUpdater= new Runnable()
{
public void run()
{
displayElapsedTime(System.currentTimeMillis() - Stopwatch.this.startTime);
}
};
public void actionPerformed(ActionEvent ae)
{
if(isRunning)
{
long elapsed= System.currentTimeMillis() - startTime;
isRunning= false;
try
{
updater.join();
// Wait for updater to finish
}
catch(InterruptedException ie) {}
displayElapsedTime(elapsed);
// Display the end-result
}
else
{
startTime= System.currentTimeMillis();
isRunning= true;
updater= new Thread(this);
updater.start();
}
}
private void displayElapsedTime(long elapsedTime)
{
startStopButton.setText(timerFormat.format(new java.util.Date(elapsedTime)));
}
public void run()
{
try
{
while(isRunning)
{
SwingUtilities.invokeAndWait(displayUpdater);
Thread.sleep(50);
}
}
catch(java.lang.reflect.InvocationTargetException ite)
{
ite.printStackTrace(System.err);
// Should never happen!
}
catch(InterruptedException ie) {}
// Ignore and return!
}
public Stopwatch()
{
startStopButton.addActionListener(this);
getContentPane().add(startStopButton);
setSize(100,50);
setVisible(true);
}
public static void main(String[] arg)
{
new Stopwatch().addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}

----------------------------------------------------------------------------------------------------------------------------------------------------

This what I have for the Stopwatch.html file...but I'm not sure how it ties into the Stopwatch.java file? Like what's the point of it...

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Stopwatch</title>
<meta charset="ISO-8859-1">
</head>
  
<body>
<applet code="Stopwatch.class" width="320" height="120"></applet>
</body>
</html>

I've posted this question multiple times and can't seem to get an answer that makes sense. Please please please someone help me!!

Explanation / Answer

i have the code you asked for stopwatch.html

<section>

<input type="radio" name="controls" id="start">

<input type="radio" name="controls" id="stop">

<input type="radio" name="controls" id="reset">

<div class="stopwatch">

<div class="cell">

<span class="num ten ten_hour">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num ten hour">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num">:</span>

</div>

<div class="cell">

<span class="num sex ten_minu">0 1 2 3 4 5</span>

</div>

<div class="cell">

<span class="num ten minu">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num">:</span>

</div>

<div class="cell">

<span class="num sex ten_sec">0 1 2 3 4 5</span>

</div>

<div class="cell">

<span class="num ten sec">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num">:</span>

</div>

<div class="cell">

<span class="num ten hund_mill">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num ten ten_mill">0 1 2 3 4 5 6 7 8 9</span>

</div>

<div class="cell">

<span class="num ten mill">0 1 2 3 4 5 6 7 8 9</span>

</div>

</div>

<div class="control">

<label for="start">Start</label>

<label for="stop">Stop</label>

<label for="reset">Reset</label>

</div>

</section>

<script src="style.js"></script>

<script>

if (document.location.search.match(/type=embed/gi)) {

window.parent.postMessage('resize', "*");

}

</script>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote