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, 21.06.2019 18:10
For each of the following claims, determine whether they are true or false. justify your determination (show your work). if the claim is false, state the correct asymptotic relationship as o, θ, or ω. unless otherwise specified, lg is log2.(a) (b) (c) (d) (e) (f) (g) (h) (i) (j)n+1 =22n =2n =1 =ln2 n =n2 +2n−4 =33n = 2n+1 =√n = 10100 =o(n4) o(2n)θ(2n+7 ) o(1/n)θ(lg2 n) ω(n2 )θ(9n ) θ(2n lg n )o(lg n) θ(1)
Answers: 1
question
Computers and Technology, 22.06.2019 02:00
Aletter or menu command that starts an action when the user presses the designated letter and the alt key together is called what?
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
Describe three characteristics of at-risk drivers. a. b. c. describe three characteristics of safe drivers. a. b. c. describe three driver errors that could cause a collision. a. b. c. how will this information affect you as a driver now and in the future? (2-3 sentences)
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