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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 24.06.2019 00:30, Auttyrain3929
Afiling system in which an intermediary source of reference, such as a file card, must be consulted to locate specific files is called a(n) system. a. shelf filing b. direct filing c. indirect filing d. shingling
Answers: 1
image
Computers and Technology, 24.06.2019 03:00, 2020IRodriguez385
With editing, word automatically displays a paste options button near the pasted or moved text. a. cut-and-paste b. drag-and-drop c. inline d. copy-and-carry
Answers: 1
image
Computers and Technology, 24.06.2019 21:50, carter4026
The use of phrases, fragments, and punctuation can influence the mood of a passage; keeping this in mind, how would you describe the mood of the followingpassage? "fog on the essex marshes, fog on the kentish heights, fog creeping into the cabooses of collier-brigs; fog lying out on the yards, and hovering in the riggingof great ships; fog drooping on the gunwales of barges and small boats. fog in the eyes and throats of ancient greenwich pensioners, wheezing by thefiresides of their wards; fog in the stem and bowl of the afternoon pipe of the wrathful skipper; fog cruelly pinching the toes and fingers of his shivering little'prentice boy on deck." (5 points)
Answers: 2
image
Computers and Technology, 25.06.2019 08:30, kammie89
How do i comment on answers? there's one answer i'm confused about but i don't know how to comment on it
Answers: 2
You know the right answer?
The stopwatchlabel component from section 12.4.5 in the textbook displays the text "" when the stop...

Questions in other subjects:

Konu
Mathematics, 05.03.2021 19:10
Konu
Arts, 05.03.2021 19:10
Konu
Mathematics, 05.03.2021 19:10
Konu
Mathematics, 05.03.2021 19:10