Question

JavaFX Programming Assignment

Create a countdown timer with at least 3 text items to appear (minutes, seconds, and milliseconds). Start at 2 minutes. Code needed to add to a gaming program which needs to count down during each level. I've shown the general idea below.

TIME O0 00:000 P1 2 3 4 0 LAPI ! 3 mphRelated image

TIME O0 00:000 P1 2 3 4 0 LAPI ! 3 mph
0 0
Add a comment Improve this question Transcribed image text
Answer #1

catch ertends づFrame euplenert ublic clays top Pauivati Threol updatirz ubic vo catch (? Dupay the ed-resulStart TiieS sRunning true Stol ngveuitiu, neteA.dieał (displayupdate+)ソ Thread. Sleep(ל לפ) public sopoae Set Size(re/s) SIy

This will Reset Your button to two minutes every time you pressed it and it will count backwards.


 
  1. import java.awt.event.*;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. public class Stopwatch extends JFrame implements ActionListener, Runnable
  5. {
  6. private long startTime;
  7. private final static java.text.SimpleDateFormat timerFormat = new java.text.SimpleDateFormat("MM : ss : SSS");
  8. private final JButton startStopButton= new JButton("Start/stop");
  9. private Thread updater;
  10. private boolean isRunning= false;
  11. private final Runnable displayUpdater= new Runnable()
  12. {
  13. public void run()
  14. {
  15. displayElapsedTime(Stopwatch.this.startTime - System.currentTimeMillis());
  16. }
  17. };
  18. public void actionPerformed(ActionEvent ae)
  19. {
  20. if(isRunning)
  21. {
  22. long elapsed= startTime - System.currentTimeMillis() ;
  23. isRunning= false;
  24. try
  25. {
  26. updater.join();
  27. // Wait for updater to finish
  28. }
  29. catch(InterruptedException ie) {}
  30. displayElapsedTime(elapsed);
  31. // Display the end-result
  32. }
  33. else
  34. {
  35. startTime= 2*60*1000+System.currentTimeMillis();
  36. isRunning= true;
  37. updater= new Thread(this);
  38. updater.start();
  39. }
  40. }
  41. private void displayElapsedTime(long elapsedTime)
  42. {
  43. startStopButton.setText(timerFormat.format(new java.util.Date(elapsedTime)));
  44. }
  45. public void run()
  46. {
  47. try
  48. {
  49. while(isRunning)
  50. {
  51. SwingUtilities.invokeAndWait(displayUpdater);
  52. Thread.sleep(50);
  53. }
  54. }
  55. catch(java.lang.reflect.InvocationTargetException ite)
  56. {
  57. ite.printStackTrace(System.err);
  58. // Should never happen!
  59. }
  60. catch(InterruptedException ie) {}
  61. // Ignore and return!
  62. }
  63. public Stopwatch()
  64. {
  65. startStopButton.addActionListener(this);
  66. getContentPane().add(startStopButton);
  67. setSize(100,50);
  68. setVisible(true);
  69. }
  70. public static void main(String[] arg)
  71. {
  72. new Stopwatch().addWindowListener(new WindowAdapter()
  73. {
  74. public void windowClosing(WindowEvent e)
  75. {
  76. System.exit(0);
  77. }
  78. });
  79. }
  80. }
Add a comment
Know the answer?
Add Answer to:
JavaFX Programming Assignment Create a countdown timer with at least 3 text items to appear (minutes, seconds, and milli...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer all questions thank you Warrings appear when half the time, 5 minutes, 1 minute,...

    Please answer all questions thank you Warrings appear when half the time, 5 minutes, 1 minute, and 30 seconds temain Multiple Altempts Not allowed. This test can only be taken once Force Completion This test can be saved and resumed at any point unil time has expired. The timer will continue to s Remaining Time: 1 hour, 56 minutes, 51 seconds. Question Completion Status erism Moving to another question will save this response. as / Question 25 Which of the...

  • Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global...

    Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global variables here. void array_stats() { // Insert your solution here. } #include <stdlib.h> #include <time.h> int main() { // Simulate the test setup process. srand( time( NULL ) ); for ( int i = 0; i < 32; i++ ) { val[i] = rand(); } val_count = rand(); val_mean = rand(); val_min = rand(); val_max = rand(); // Call submitted code. array_stats(); // Display...

  • just one example/demonstration! Data needed to be calculated is in highlighted in green boxes. And I...

    just one example/demonstration! Data needed to be calculated is in highlighted in green boxes. And I highlighted in red an equation (not sure if thats what you use to calculate it) And ignore the lab instructions on completeing a graph!! I already know how to do that in excel, just curious how Ln (relative rate) and 1/T in K^-1 is calculated by hand* here is the rest of that lab leading up to the question as I know its typically...

  • 3. If 15.0 mL of 0.125 M phosphoric acid is titrated with 0.100 M NaOH, what...

    3. If 15.0 mL of 0.125 M phosphoric acid is titrated with 0.100 M NaOH, what volume of the titrant (in mL) must be added to completely neutralize the acid? Show all of your work (including the chemical equation). (1 point) Post-lab Questions: Experiment #9: Acid-Base Titrations Student Learning Objectives : Students will gain practice with the accurate preparation of solutions. Students will perform acid-base titrations and prepare titration curves. Students will identify strong and weak acids by the shapes...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT