subject

The stopwatchlabel component from section 12.4.5 in the textbook displays the text "" when the stop watch is running. it would be nice if it displayed the elapsed time since the stop watch was started. for that, you need to create a timer (see section 6.5.1 in the textbook.) add a timer to the original source code, stopwatchlabel. java in the code directory, to drive the display of the elapsed time in seconds. create the timer in the mousepressed() routine when the stop watch is started. stop the timer in the mousepressed() routine when the stop watch is stopped. the elapsed time won't be very accurate anyway, so just show the integral number of seconds. you only need to set the text a few times per second. for the timer method, use a delay of 200 milliseconds for the timer. here is an applet that tests one possible solution to this exercise: import java. awt. event.*; import javax. swing.*; /*** a custom component that acts as a simple stop-watch. when the user clicks* on it, this componet starts timing. when the user clicks again,* it displays the time between the two clicks. clicking a third time* starts another timer, etc. while it is timing, the label just* displays the message "".*/public class stopwatchlabel extends jlabel implements mouselistener {private long starttime; // start time of timer.// (time is measured in milliseconds.)private boolean running; // true when the timer is running./*** constructor sets initial text on the label to* "click to start timer." and sets up a mouse listener* so the label can respond to clicks.*/public stopwatchlabel() {super(" click to start timer. ", jlabel. center); addmouselistener(this); }/*** tells whether the timer is currently running.*/public boolean isrunning() {return running; }/*** react when the user presses the mouse by starting* or stopping the timer and changing the text that* is shown on the label.*/public void mousepressed(mouseevent evt) {if (running == false) {// record the time and start the timer. running = true; starttime = evt. getwhen(); // time when mouse was clicked. settext(""); }else {// stop the timer. compute the elapsed time since the// timer was started and display it. running = false; long endtime = evt. getwhen(); double seconds = (endtime - starttime) / 1000.0; settext("time: " + seconds + " sec."); }}public void mousereleased(mouseevent evt) { }public void mouseclicked(mouseevent evt) { }public void mouseentered(mouseevent evt) { }public void mouseexited(mouseevent evt) { }}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:00
What role do chromosomes play in inheritance?
Answers: 1
question
Computers and Technology, 22.06.2019 22:00
Researchers measured the data speeds for a particular smartphone carrier at 50 airports. the highest speed measured was 78.1 mbps. the complete list of 50 data speeds has a mean of x overbarequals16.11 mbps and a standard deviation of sequals18.65 mbps. a. what is the difference between carrier's highest data speed and the mean of all 50 data speeds? b. how many standard deviations is that [the difference found in part (a)]? c. convert the carrier's highest data speed to a z score. d. if we consider data speeds that convert to z scores between minus2 and 2 to be neither significantly low nor significantly high, is the carrier's highest data speed significant? a. the difference is nothing mbps.
Answers: 3
question
Computers and Technology, 23.06.2019 20:30
What is the biggest difference between section breaks and regular page breaks
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
You know the right answer?
The stopwatchlabel component from section 12.4.5 in the textbook displays the text "" when the stop...
Questions
question
Mathematics, 16.04.2020 01:47
Questions on the website: 13722365