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 10:50
Using least squares fitting, you are to fit the data sets to the following models and solve for the parameters ai , where i is the index of the parameter. the input/output data for the systems are linked in the bblearn site. for each of the systems use matlab to plot the supplied data vs. the model fit on one plot. include your code in the solutions. (a) linear fit "lineardata.mat" y=a1x^3 + a2x^2 + a3x + a4 (b) plant fit "plantdata.mat g(s) = a1/(s + a2)
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
Ihave an iphone 8plus should i get another phone like samsung note 9 or s9 ? ?
Answers: 2
question
Computers and Technology, 22.06.2019 20:00
What is the term for water wave that is created by an underwater earthquake
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
One of your customers wants you to build a personal server that he can use in his home. one of his concerns is making sure he has at least one backup of their data stored on the server in the event that a disk fails. you have decided to back up his data using raid. since this server is for personal use only, the customer wants to keep costs down. therefore, he would like to keep the number of drives to a minimum. which of the following raid systems would best meet the customer's specifications? a. raid 0 b. raid 1 c. raid 5 d. raid 10
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, 22.09.2019 01:50
question
Mathematics, 22.09.2019 01:50
Questions on the website: 13722365