Java stopwatch ⏱️

preview_player
Показать описание
java stopwatch program

#java #stopwatch #program

// ***************************************************
public class Main {

public static void main(String[] args) {

Stopwatch stopwatch = new Stopwatch();

}
}
// ***************************************************

public class Stopwatch implements ActionListener{

JFrame frame = new JFrame();
JButton startButton = new JButton("START");
JButton resetButton = new JButton("RESET");
JLabel timeLabel = new JLabel();
int elapsedTime = 0;
int seconds =0;
int minutes =0;
int hours =0;
boolean started = false;

Timer timer = new Timer(1000, new ActionListener() {

public void actionPerformed(ActionEvent e) {

elapsedTime=elapsedTime+1000;
hours = (elapsedTime/3600000);
minutes = (elapsedTime/60000) % 60;
seconds = (elapsedTime/1000) % 60;

}

});


Stopwatch(){





}

@Override
public void actionPerformed(ActionEvent e) {


if(started==false) {
started=true;
start();
}
else {
started=false;
stop();
}

}
started=false;
reset();
}

}

void start() {
}

void stop() {
}

void reset() {
elapsedTime=0;
seconds =0;
minutes=0;
hours=0;
}

}
Рекомендации по теме
Комментарии
Автор

public class Main {

public static void main(String[] args) {

Stopwatch stopwatch = new Stopwatch();

}
}
//
import java.awt.*;

import java.awt.event.*;
import javax.swing.*;

public class Stopwatch implements ActionListener{

JFrame frame = new JFrame();
JButton startButton = new JButton("START");
JButton resetButton = new JButton("RESET");
JLabel timeLabel = new JLabel();
int elapsedTime = 0;
int seconds =0;
int minutes =0;
int hours =0;
boolean started = false;
String seconds_string = String.format("%02d", seconds);
String minutes_string = String.format("%02d", minutes);
String hours_string = String.format("%02d", hours);

Timer timer = new Timer(1000, new ActionListener() {

public void actionPerformed(ActionEvent e) {


hours =
minutes = (elapsedTime/60000) % 60;
seconds = (elapsedTime/1000) % 60;
seconds_string = String.format("%02d", seconds);
minutes_string = String.format("%02d", minutes);
hours_string = String.format("%02d", hours);


}

});


Stopwatch(){


timeLabel.setBounds(100, 100, 200, 100);
timeLabel.setFont(new Font("Verdana", Font.PLAIN, 35));

timeLabel.setOpaque(true);


startButton.setBounds(100, 200, 100, 50);
startButton.setFont(new Font("Ink Free", Font.PLAIN, 20));



resetButton.setBounds(200, 200, 100, 50);
resetButton.setFont(new Font("Ink Free", Font.PLAIN, 20));



frame.add(startButton);
frame.add(resetButton);
frame.add(timeLabel);


frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {

{

if(started==false) {
started=true;

start();
}
else {
started=false;

stop();
}

}
{
started=false;

reset();
}

}

void start() {
timer.start();
}

void stop() {
timer.stop();
}

void reset() {
timer.stop();
elapsedTime=0;
seconds =0;
minutes=0;
hours=0;
seconds_string = String.format("%02d", seconds);
minutes_string = String.format("%02d", minutes);
hours_string = String.format("%02d", hours);

}

}//

BroCodez
Автор

MORE OF THIS! Very nice. As someone who is relatively new to coding I love to write the code with your help, and then being able to understand it by myself. For me, it is a great way of learning, keep this up please!

Sam-mosm
Автор

I practiced your code by using 2 hours and I wrote it for 67 times. Now I feels coding is very easy, and coding has greatly improved my English skills too.

girl
Автор

Around half of the video, I stopped it and completedthe rest of the program by myself. and it worked :) I'm learning a lot thanks to your series! <3

angelcastineira
Автор

This is the best Java video I have seen, thank you very much.

elgatoJNF
Автор

It was very helpful and i learned some new things.
Great video

vedpatel
Автор

Thanks for the tutorial it is pretty clear and easy to understand, I learn a lot thanks to you !

boubou
Автор

Bro am really benefiting a lot from your lectures. thanks

ousmanjallow
Автор

Very good! Now I beginning to understand how a Timer in Java works. Hopefully I can use it to anymate my wavegenerator I wrote in both VB and Java. Thanks for this wonderful video!

SwingDanceOpa
Автор

Wow bro.. I am learning a lot. Its a very best java coding tutorials ever. Thank you a lot.

primeoptumas
Автор

Such a great and helpful video! Thank you!

customministrymusic
Автор

thank you, learning from watching videos is the best way to learn for me, and this is a really well made one, good job Bro Code bro

vitobahariia
Автор

This is amazing !!!
please keep up up a good work, and make more projects

admoonhermiz
Автор

Thanks mate, helped me a lot for my 3rd year.

PetronasBoyy
Автор

Bro code thank you so much make a playlist for swing stuff you can do you are very underrated subbed

n
Автор

Very useful video. New in java, wanting to make something new and u helped me a lot with it. Thks bro, keep this content :)

samuel
Автор

Muchas gracias por esta clase, me ayudo mucho con mi proyecto, tendria mi duda en la cuestion de poder hacerlo metodo para poderlo usar con cualquier ob

solracnauj
Автор

This was such a good video, I was looking for something exactly like this, and this is awsome. Could you make a video for a Timer in Java too(in case you haven't done it already)?

vortexjl
Автор

Thank you bro.I learned alot in your tutorial

motivation.
Автор

Thanks for the vid - im study programming and this is still helpful!
Where you get your Eclipse theme? I have already a black one, but my overlay around my code panel is still white :/

silvergodanalyser