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 00:40
Reading characters and strings from the keyboard: consider the following c++ program 1. #include 2. #include 3. using namespace std; 4. mystring1 5. 6. int main() 7. { 8. 9. string mystring1, mystring2; mychar1 10. 11. 12. char mychar1, mychar2; 13. 14. cout< < "enter a string: "; mychar2 15. 16. cin> > mystring1; // 17. cin.get(mychar1); 18. cin> > mychar2; 19. getline(cin,mystring2); mystring2 20. 21. 22. cout<
Answers: 1
question
Computers and Technology, 22.06.2019 13:00
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen tool
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
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, 21.06.2019 21:10
Questions on the website: 13722362