Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java problem!! Instructions: 1. Initial configuration The application shall create a window with two buttons and a label. The first button shall be labeled Start.

Java problem!!

Instructions:

1. Initial configuration

The application shall create a window with two buttons and a label.

The first button shall be labeled "Start".

The second buttons shall be labeled "Reset".

The label shall display the elapsed time, in 0.01 second increments.

The text in the label should be centered vertically and horizontally.

The label shall be easy to read. This example uses 36-point, bold Arial as the font. (Hint: see java.awt.Font)

The initial window looks like this:

image text in transcribed

2. Clicking the Start button:

Clicking the Start button, starts the timer.

The button caption changes to "Pause".

The label updates each 0.01 of a second to reflect elapsed time.

Here is an example of what the window looks like after the Start button is clicked:

image text in transcribed

3. Clicking the Pause button:

Clicking the Pause button, stops the timer.

The button caption changes to "Continue".

The output label stops counting elapsed time.

Here is an example of what the window looks like after the Stop button is clicked:

image text in transcribed

4. Clicking the Continue Button

Clicking the Continue button, restarts the timer.

The button caption changes to "Pause".

The output label resumes counting elapsed time, adding to the elapsed time. That is, the next update will indicate 0.01 seconds after the time displayed during pause

image text in transcribed

5. Clicking the Reset Button

Clicking the Reset button, returns the timer to the initial configuration.

If the timer is running, it is stopped.

The caption of the first button changes to "Start".

The output label reverts to "0.00 seconds".

image text in transcribed

Note:

Use java.lang.Thread rather than java.util.Timer

You may assume that the Thread.sleep is accurate enough for this implementation. That is, you can assume that every call the Thread.sleep(10) is 10 milliseconds long. So, after calling Thread.sleep(10), the display can be updated by 0.01 seconds.

Here is my code so far:

public class MyTimer extends javax.swing.JFrame { public MyTimer(){ super("My Timer"); setLocation(25, 25); setSize(400, 300); setDefaultCloseOperation(DISPOSE_ON_CLOSE); // create a toolbar javax.swing.JPanel toolbar = new javax.swing.JPanel(); add(toolbar, java.awt.BorderLayout.NORTH); // create a button javax.swing.JButton button1; javax.swing.JButton button2; button1 = new javax.swing.JButton("Start"); button2 = new javax.swing.JButton("Reset"); toolbar.add(button1); toolbar.add(button2); // finally, set the window to be visible setVisible(true); }

/** * The application method * @param args The command-line arguments */ public static void main(String[] args) { new MyTimer(); } }

My Timer Start Reset 0.00 Seconds

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

What do the results mean?

Answered: 1 week ago