Java stopwatch ⏱️

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ธ.ค. 2024

ความคิดเห็น • 125

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +35

    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) {

    elapsedTime=elapsedTime+1000;
    hours = (elapsedTime/3600000);
    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);
    timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string);

    }

    });


    Stopwatch(){

    timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string);
    timeLabel.setBounds(100,100,200,100);
    timeLabel.setFont(new Font("Verdana",Font.PLAIN,35));
    timeLabel.setBorder(BorderFactory.createBevelBorder(1));
    timeLabel.setOpaque(true);
    timeLabel.setHorizontalAlignment(JTextField.CENTER);

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

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

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

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

    @Override
    public void actionPerformed(ActionEvent e) {

    if(e.getSource()==startButton) {

    if(started==false) {
    started=true;
    startButton.setText("STOP");
    start();
    }
    else {
    started=false;
    startButton.setText("START");
    stop();
    }

    }
    if(e.getSource()==resetButton) {
    started=false;
    startButton.setText("START");
    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);
    timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string);
    }
    }// ***************************************************

    • @jaxtonabraham4778
      @jaxtonabraham4778 3 ปีที่แล้ว

      Instablaster...

    • @joyceasante8292
      @joyceasante8292 ปีที่แล้ว

      Practicing...😓
      public class Main
      {
      public static void main (String[]args)
      {
      Stopwatch stopwatch = new Stopwatch ();
      Stopwatch stopwatch2 = new Stopwatch();
      }
      }
      ***************************
      import java.awt.event.*;
      import java.awt.*;
      import javax.swing.*;
      public class Stopwatch implements ActionListener{
      JFrame frame = new JFrame();
      JButton startButton = new JButton("Start");
      JButton stopButton = new JButton("Stop");
      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){
      elapsedTime = elapsedTime +1000;
      hours = (elapsedTime/3600000)%60;
      minutes = (elapsedTime/60000)%60;
      seconds = (elapsedTime/1000);
      seconds_string = String.format("%02d",seconds);
      minutes_string = String.format("%02d",minutes);
      hours_string = String.format("%02d",hours);
      timeLabel.setText(hours_string+ ": "+minutes_string+":"+hours_string);

      }
      });
      Stopwatch(){
      timeLabel.setText(hours_string+ ":"+minutes_string+":"+hours_string);
      timeLabel.setBounds(100,100,200,100);
      timeLabel.setFont(new Font("Times New Roman", Font.PLAIN,18));
      timeLabel.setBorder(BorderFactory.createBevelBorder(1));
      timeLabel.setOpaque(true);
      timeLabel.setHorizontalAlignment(JTextField.CENTER);
      startButton.setBounds(100,200,100,50);
      startButton.setFont(new Font("Hellvetica", Font.PLAIN,12));
      startButton.setFocusable(false);
      startButton.addActionListener(this);
      resetButton.setBounds(200,200,100,50);
      resetButton.setFont(new Font("Hellvetica", Font.PLAIN,12));
      resetButton.setFocusable(false);
      resetButton.addActionListener(this);
      frame.add(startButton);
      frame.add(timeLabel);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(380,380);
      frame.setLayout(null);
      frame.setVisible(true);
      }

      @Override
      public void actionPerformed(ActionEvent e){
      if(e.getSource()== startButton){
      if(started==false){
      started=true;
      startButton.setText("Stop");
      start();
      }
      else{
      started=false;
      startButton.setText("Start");
      stop();
      }
      }
      if(e.getSource()==resetButton){
      started=false;
      startButton.setText("Start");
      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);
      timeLabel.setText(hours_string+ ": "+minutes_string+":"+hours_string);

      }
      }

    • @rob.it0717
      @rob.it0717 ปีที่แล้ว

      Thx very much, helped me a lot with my chess clock in my school project :)

  • @girl6994
    @girl6994 4 ปีที่แล้ว +39

    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.

    • @adeyemiadeolu2961
      @adeyemiadeolu2961 4 ปีที่แล้ว +3

      is this an effective way to learn coding

    • @bewaryoftherabbithole8011
      @bewaryoftherabbithole8011 3 ปีที่แล้ว +2

      yeah it has also improved my English skills a bit xD

    • @kkaragoz
      @kkaragoz 3 ปีที่แล้ว +2

      Keep repeating. You can conquer the world with this determination :)

  • @angelcastineira2561
    @angelcastineira2561 4 ปีที่แล้ว +15

    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!

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +9

      awesome dude! It's probably natural for you now

  • @Sam-mo9sm
    @Sam-mo9sm 3 ปีที่แล้ว +8

    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!

  • @elgatoJNF
    @elgatoJNF 2 ปีที่แล้ว

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

  • @Dygit
    @Dygit 4 ปีที่แล้ว +4

    Your videos deserve more attention

  • @vedP-02
    @vedP-02 4 ปีที่แล้ว +2

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

  • @elionayzuridasilveira4140
    @elionayzuridasilveira4140 2 หลายเดือนก่อน

    Thank you for this new lesson

  • @primeoptumas8435
    @primeoptumas8435 3 ปีที่แล้ว

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

  • @ousmanjallow1643
    @ousmanjallow1643 4 ปีที่แล้ว +1

    Bro am really benefiting a lot from your lectures. thanks

  • @solracnauj19
    @solracnauj19 2 ปีที่แล้ว

    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

  • @samuel43834
    @samuel43834 4 ปีที่แล้ว +2

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

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +1

      thanks for watching Samuel!

  • @vitobahari2ia079
    @vitobahari2ia079 3 ปีที่แล้ว +1

    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

  • @boubou3171
    @boubou3171 2 ปีที่แล้ว

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

  • @admoonhermiz1
    @admoonhermiz1 ปีที่แล้ว

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

  • @SwingDanceOpa
    @SwingDanceOpa 2 ปีที่แล้ว

    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!

  • @cate01a
    @cate01a 4 ปีที่แล้ว +3

    you make the best tutorials :D

  • @customministrymusic4954
    @customministrymusic4954 4 ปีที่แล้ว +2

    Such a great and helpful video! Thank you!

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks for watching!

  • @anonimanonim1223
    @anonimanonim1223 2 ปีที่แล้ว

    Nice tutotial.

  • @parsachavoshu8797
    @parsachavoshu8797 2 ปีที่แล้ว

    Greatttttt!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @SimonZhao-sq1wz
    @SimonZhao-sq1wz 2 ปีที่แล้ว

    Hi Bro Code! thank you for this tutorial. one small thing: I notice that you write the following code multiple times, but I think you dont have to because they are global variable:
    String seconds_string = String.format("%02d", seconds);
    String mins_string = String.format("%02d", mins);
    String hours_string = String.format("%02d", hours);
    all in all, rock solid tutorial!

    • @SmallSpoonBrigade
      @SmallSpoonBrigade ปีที่แล้ว

      Personally, I'd just store time as a single variable and have a method to take that and convert it to the appropriate format for display. I assume he did that because global variables are best kept to a minimum in case you want or need to refactor later and didn't want to go through the process of creating a specific method for dealing with that.

  • @kemann3815
    @kemann3815 3 ปีที่แล้ว

    Great 👍

  • @n9583
    @n9583 3 ปีที่แล้ว

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

  • @mozcoder
    @mozcoder ปีที่แล้ว

    Amazing tutorial, thank you Bro.

  • @365motivation.9
    @365motivation.9 2 ปีที่แล้ว

    Thank you bro.I learned alot in your tutorial

  • @yasinmohammadi8
    @yasinmohammadi8 4 ปีที่แล้ว +1

    That video was really helpful

  • @vedanshisahay9179
    @vedanshisahay9179 2 ปีที่แล้ว

    I just love u channel 🔥🔥

  • @PetronasBoyy
    @PetronasBoyy 3 ปีที่แล้ว

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

  • @nobodyanonimus7953
    @nobodyanonimus7953 2 ปีที่แล้ว

    nice tutorial

  • @sujanbasnet8243
    @sujanbasnet8243 4 ปีที่แล้ว

    Thanks for making this video

  • @gautampareek5076
    @gautampareek5076 4 ปีที่แล้ว +2

    Can we add milli second in label,how?

  • @socaljusticewarrior558
    @socaljusticewarrior558 3 ปีที่แล้ว

    I've already subscribed, but I am still going to like and comment. Liking is easy enough, but it'll be a while before I think of something to comment

  • @justinjohnson422
    @justinjohnson422 3 ปีที่แล้ว

    This tutorial was awesome!

  • @kirsty6108
    @kirsty6108 4 ปีที่แล้ว +4

    can you make a log in system next? That would be very helpful

    • @girl6994
      @girl6994 4 ปีที่แล้ว

      Kirsty Holmes that’s easier to make it on HTML. And we deal with it by java in servlet

    • @girl6994
      @girl6994 4 ปีที่แล้ว

      But you can simply use JOptionpane.showinputdialog to make it or use Scanner and file output stream to make a simple demo.

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      I'll see what I can come up with

  • @vortexjl9680
    @vortexjl9680 3 ปีที่แล้ว +2

    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)?

    • @axle4565
      @axle4565 2 ปีที่แล้ว

      this IS for java

  • @zunairaiqbal1490
    @zunairaiqbal1490 4 ปีที่แล้ว +1

    Thank uhhh it helped me alotttt❤️🤔

  • @silvergodanalyser7762
    @silvergodanalyser7762 3 ปีที่แล้ว +3

    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 :/

  • @anonymous-ws5cv
    @anonymous-ws5cv 2 ปีที่แล้ว

    Thankyou so much

  • @Foxlaren
    @Foxlaren 3 ปีที่แล้ว +3

    When I try to pass two arguments to the timer it says
    "The constructor Timer(int, new ActionListener(){}) is undefined"
    I got this error for the second time ,even in that 2D animation video of the same playlist ,
    What can I do :(
    @Bro Code

    • @APDesignFXP
      @APDesignFXP 2 ปีที่แล้ว +3

      It's seems like you have used the wrong import of Timer, make sure to import javax.swing.Timer; and not java.awt.Timer;

  • @aarushbasak4941
    @aarushbasak4941 2 ปีที่แล้ว

    Good jOB BRO

  • @dr1lltrckz147
    @dr1lltrckz147 3 ปีที่แล้ว

    What if I wanted the timer to change every millisecond? The integer conversion in nanoseconds is too large of a number in Java, what should I do?

  • @솜쿤-g6o
    @솜쿤-g6o 2 ปีที่แล้ว +1

    한국인은 저 밖에...?

  • @theslipperypot8o674
    @theslipperypot8o674 3 ปีที่แล้ว

    I know this is late, but how would the code look if you wanted to measure milliseconds as well?

  • @NikolasRamjet
    @NikolasRamjet ปีที่แล้ว

    Cheers Bro

  • @AbdirazakAli1
    @AbdirazakAli1 3 ปีที่แล้ว

    420,420 because it's funny number. great tutorial

  • @princekumarmehta8788
    @princekumarmehta8788 3 ปีที่แล้ว

    Thank you so much bro...

  • @sergeyb6071
    @sergeyb6071 4 ปีที่แล้ว +2

    Great video Bro! Any idea why JButton and JFrame has a slight delay of about a second to load when the app is opened?

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +1

      Hmmm I'm not sure what caused that

  • @changeme1832
    @changeme1832 2 ปีที่แล้ว

    Nice bro :-D

  • @gaetanbarette3339
    @gaetanbarette3339 4 ปีที่แล้ว +1

    thanks

  • @imie5762
    @imie5762 2 ปีที่แล้ว

    Is there a way to also implement miliseconds? I tried changing timer delay to 1ms and increment elapsedTime by 1ms, but it doesnt work. Stopwatch starts counting miliseconds really slow for some reason.

  • @Stryker-ye7wn
    @Stryker-ye7wn 3 ปีที่แล้ว

    Not sure if u still check comments but how would I add milliseconds into the stopwatch?

  • @hudihu5395
    @hudihu5395 2 ปีที่แล้ว

    Yeah Bro, 4:20 is really an interesting number lol

  • @trendbitess
    @trendbitess 3 ปีที่แล้ว

    nice tutorial , you teach very smooth well done. I found one small bug here. when second counts if i wait 500 milliseconds and push stop button and again start stopwatch wait 1000 milliseconds to count one second further. how can we fix this issue?

  • @eugenezuev7349
    @eugenezuev7349 5 หลายเดือนก่อน

    sweet

  • @maxwong1768
    @maxwong1768 2 ปีที่แล้ว

    I make the stopwatch by my own self before look at your solution . I cant believe that I can do it .
    Class : Stopwatch
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Timer;
    import java.util.TimerTask;

    public class Stopwatch implements ActionListener {

    JFrame frame ;
    JLabel timeLabel ;
    JButton startButton , stopButton , resetButton ;

    Timer timer ;
    TimerTask task ;

    String time ;
    int secOne , secTen , minOne , minTen , hrOne , hrTen ;
    // store the previous state : start = 1 , stop = 0 , reset = -1 .
    int state = -1 ;

    Stopwatch() {

    timeLabel = new JLabel("00:00:00") ;
    timeLabel.setFont(new Font("MV Boli" , Font.PLAIN , 50)) ;
    timeLabel.setForeground(Color.white) ;

    startButton = new JButton("Start") ;
    stopButton = new JButton("Stop") ;
    resetButton = new JButton("Reset") ;

    startButton.addActionListener(this) ;
    stopButton.addActionListener(this) ;
    resetButton.addActionListener(this) ;

    frame = new JFrame("Stopwatch") ;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    frame.setSize(500 , 500) ;
    frame.setVisible(true) ;
    frame.setLocationRelativeTo(null) ;
    frame.setLayout(new FlowLayout()) ;
    frame.getContentPane().setBackground(Color.black) ;

    frame.add(timeLabel) ;

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

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    if (e.getSource() == startButton) {
    System.out.println("test2") ;
    showCount() ;
    // prevent multiple task threads run together if user clicks [Start] for too many times .
    if (state != 1) {
    timer.scheduleAtFixedRate(task , 1000 , 1000) ; // (TimerTaskName , startTime/delay , repeatPeriod)
    }
    state = 1 ;
    }

    if (e.getSource() == stopButton) {
    if (state == 1) {
    timer.cancel();
    }
    state = 0 ;
    }

    if (e.getSource() == resetButton) {
    secOne = 0 ;
    secTen = 0 ;
    minOne = 0 ;
    minTen = 0 ;
    hrOne = 0 ;
    hrTen = 0 ;

    time = time.format("%d%d:%d%d:%d%d" , hrTen , hrOne , minTen , minOne , secTen , secOne) ;
    timeLabel.setText(time) ;

    if (state == 1) {
    timer.cancel() ;
    }

    state = -1 ;
    }
    }

    public void start() {

    }

    public void stop() {

    }

    public void reset() {

    }

    public void showCount() {
    System.out.println("test1") ;

    timer = new Timer() ;
    task = new TimerTask() { // TimerTask is an abstract class .
    @Override
    public void run() {
    secOne += 1 ;
    if (secOne == 10) {
    secOne = 0 ;
    secTen += 1 ;
    if (secTen == 6) {
    secTen = 0 ;
    minOne += 1 ;
    if (minOne == 10) {
    minOne = 0 ;
    minTen += 1 ;
    if (minTen == 6) {
    minTen = 0 ;
    hrOne += 1 ;
    if (hrOne == 10) {
    hrOne = 0 ;
    hrTen += 1 ;
    }
    }
    }
    }
    }

    time = time.format("%d%d:%d%d:%d%d" , hrTen , hrOne , minTen , minOne , secTen , secOne) ;
    timeLabel.setText(time) ;
    }
    };
    }
    }
    Class : Main
    public class Main {

    public static void main(String[] args) {

    Stopwatch stopewatch = new Stopwatch() ;
    }

    }

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks

  • @salaheddine6556
    @salaheddine6556 4 ปีที่แล้ว

    what's the difference between Time from java.util and Time from javax.swing and even there is a third one ???

  • @alaapnair6923
    @alaapnair6923 3 ปีที่แล้ว

    Hey, what is the variable where I can try to say if the time is 10 seconds stop or do something. I say if ____ = 10 seconds

  • @raviratnakar3803
    @raviratnakar3803 3 ปีที่แล้ว +1

    I am fellow bro!

  • @EdgeLordOmen
    @EdgeLordOmen 8 หลายเดือนก่อน

    420 is a funny number caught you bro haha

  • @ibenja7515
    @ibenja7515 3 ปีที่แล้ว

    Thank you bro

  • @bartschauer7391
    @bartschauer7391 3 ปีที่แล้ว

    code very helpful and nicely explained, does anyone know how to add hundredths or thousandths of a second?
    Regards, Bart

  • @xXMaDGaMeR
    @xXMaDGaMeR 3 ปีที่แล้ว

    awesome video Bro !

  • @munisahmad9125
    @munisahmad9125 4 ปีที่แล้ว +2

    Algorithm where you at?

  • @khabbazz89
    @khabbazz89 2 ปีที่แล้ว

    Why you do not use windowbuilder?!

  • @agny369
    @agny369 3 ปีที่แล้ว

    is this implementable with java fx ?

  • @aakmsh
    @aakmsh 2 ปีที่แล้ว

    Thank you ! ❤️

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว

  • @tytuskopak3998
    @tytuskopak3998 3 ปีที่แล้ว

    Hey Bro, I'm new to coding in Java. Could you tell me how can I put two stopwathes in one window? Thanks.

  • @smarkie2910
    @smarkie2910 4 ปีที่แล้ว

    since i want to make the the stop button separate i would have to add the following right?
    JButton stopButton = new JButton("STOP");
    stopButton.setBounds(200,200,100,50);
    stopButton.setFont(new Font("Arial",Font.PLAIN,20));
    stopButton.setFocusable(false);
    stopButton.addActionListener(this);
    frame.add(stopButton);
    ?

    • @smarkie2910
      @smarkie2910 4 ปีที่แล้ว +1

      is there a way to make this work
      ?

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +1

      yeah you would want an action performed method that will check to see if the stopbutton was clicked. If so, call timer.stop();

    • @smarkie2910
      @smarkie2910 3 ปีที่แล้ว +1

      @@BroCodez is there a way to make it using just by label instead of Jlabel, our professor said not to use it as its not given in our syllabus, help?

  • @APDesignFXP
    @APDesignFXP 2 ปีที่แล้ว

    If anyone wants enhanced and optimized tutorial for this app, comment on my comment and I'd use his code for opt tutorial.

  • @jasonkress6287
    @jasonkress6287 3 ปีที่แล้ว

    I followed the tutorial exactly and even tried coping and pasting the code but my timer isnt starting.

  • @manikandanbalasubramani3172
    @manikandanbalasubramani3172 3 ปีที่แล้ว

    Hi sir! can we set up a stopwatch through rest api

  • @developerjunior446
    @developerjunior446 3 ปีที่แล้ว

    Cool!!!!

  • @augischadiegils.5109
    @augischadiegils.5109 3 ปีที่แล้ว +1

    Thanks bro :)

  • @JehanSaren
    @JehanSaren ปีที่แล้ว

    why dont make pause and resume?

  • @NatyTor
    @NatyTor 2 ปีที่แล้ว

    Awesome bro!

  • @maniron168
    @maniron168 2 ปีที่แล้ว

    oh wow i made the stop watch please asirbad me
    hahaha

  • @releNtless-eu3xc
    @releNtless-eu3xc 4 ปีที่แล้ว

    How do I add Alarm capability so that I can set an alarm? Can I also add both of these to my Clock app that you taught us before? can I combine all of them to have a proper advanced clock app? Otherwise, can you at least teach us how to make one?

  • @frgaming6711
    @frgaming6711 4 ปีที่แล้ว

    nice sir TYSM

  • @YTtopPAULO
    @YTtopPAULO 3 ปีที่แล้ว

    bro how do you open this window?
    can you tell meor tech me?

  • @ozzyyorke9851
    @ozzyyorke9851 3 ปีที่แล้ว

    hello how can u change the icon thanks

  • @yuryaraujo1612
    @yuryaraujo1612 ปีที่แล้ว

    Nice!

  • @lolnypop
    @lolnypop 9 หลายเดือนก่อน

    Comment for you so the algorithm finds you more often :D

  • @francisllaneta9536
    @francisllaneta9536 2 ปีที่แล้ว

    hi can someone tell me how to add a time lapse in this stopwatch??

  • @hanami279
    @hanami279 2 ปีที่แล้ว

    Wow!

  • @adityawaghmode4751
    @adityawaghmode4751 4 ปีที่แล้ว +1

    Hey i ran the code as it is, i even copy pasted your code and followed every step as you mentioned in this video, but the code is not running please help me?:(

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      Sure, do you have an error code at all or is something not displaying? I'm not sure where to begin helping

    • @michael54321
      @michael54321 4 ปีที่แล้ว

      @@BroCodez error: constructor Timer in class Timer cannot be applied to given types;

  • @kelloxdrc9485
    @kelloxdrc9485 2 ปีที่แล้ว

    I tried adding milliseconds, but for some reason the time goes up slower, can anybody help?

    • @kelloxdrc9485
      @kelloxdrc9485 2 ปีที่แล้ว

      Code:
      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 milliseconds =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);
      String milliseconds_string = String.format("%03d", milliseconds);

      Timer timer = new Timer(1, new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      elapsedTime++;
      hours = (elapsedTime/3600000);
      minutes = (elapsedTime/60000) % 60;
      seconds = (elapsedTime/1000) % 60;
      milliseconds = elapsedTime % 1000;
      seconds_string = String.format("%02d", seconds);
      minutes_string = String.format("%02d", minutes);
      hours_string = String.format("%02d", hours);
      milliseconds_string = String.format("%03d", milliseconds);
      timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string+":"+milliseconds_string);

      }
      });


      Stopwatch(){

      timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string+":"+milliseconds_string);
      timeLabel.setBounds(100,100,300,100);
      timeLabel.setFont(new Font("Verdana",Font.PLAIN,35));
      timeLabel.setBorder(BorderFactory.createBevelBorder(1));
      timeLabel.setOpaque(true);
      timeLabel.setHorizontalAlignment(JTextField.CENTER);

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

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

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

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(420,420);
      frame.setLayout(null);
      frame.setResizable(true);
      frame.setVisible(true);
      }

      @Override
      public void actionPerformed(ActionEvent e) {

      if(e.getSource()==startButton) {

      if(started==false) {
      started=true;
      startButton.setText("STOP");
      start();
      }
      else {
      started=false;
      startButton.setText("START");
      stop();
      }

      }
      if(e.getSource()==resetButton) {
      started=false;
      startButton.setText("START");
      reset();
      }

      }

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

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

      void reset() {
      timer.stop();
      elapsedTime=0;
      seconds =0;
      minutes=0;
      milliseconds =0;
      hours=0;
      seconds_string = String.format("%02d", seconds);
      minutes_string = String.format("%02d", minutes);
      hours_string = String.format("%02d", hours);
      milliseconds_string = String.format("%03d", milliseconds);
      timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string+":"+milliseconds_string);
      }
      }

  • @maxwong1768
    @maxwong1768 2 ปีที่แล้ว

    I have made it simple .
    Timer timer = new Timer(1000 , new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    elapsedTime += 1000 ;
    displayTime() ;
    }
    });
    public void reset() {
    timer.stop() ;
    elapsedTime = 0 ;
    displayTime() ;
    }
    public void displayTime() {
    hours = elapsedTime / 3600000 ;
    // limit the minutes below 60 .
    // e.g. 3%60=3 , 60%60=0 , 100%60=40
    minutes = (elapsedTime / 60000) % 60 ;
    // limit the seconds below 60 .
    seconds = (elapsedTime / 1000) % 60 ;

    time = String.format("%02d:%02d:%02d" , hours , minutes , seconds) ;
    timeLabel.setText(time) ;
    }

  • @ng5m0
    @ng5m0 3 ปีที่แล้ว

    how to add miliseconds?

  • @AlfiNR
    @AlfiNR ปีที่แล้ว

    dont dislike Bro Code channel

  • @zari_723
    @zari_723 ปีที่แล้ว

    hi

  • @gavblack
    @gavblack 8 หลายเดือนก่อน

    its crazy how you can watch and copy everything that he is doing line by line and it still fucks up

  • @ElectroMitch
    @ElectroMitch 2 ปีที่แล้ว

    I tried to do this but it didn't work, so I copied and pasted the code in the description to see exactly how he did it and it was still coming up with the same issue.

  • @rohansachdeva627
    @rohansachdeva627 ปีที่แล้ว

    why are you mixing kebap_case. Just stick to camelCase. Its painful for the eyes.. Anyways goodjob

  • @ElepIn
    @ElepIn 2 ปีที่แล้ว

    thx!

  • @RobotWorks
    @RobotWorks 2 ปีที่แล้ว

    I need help

    • @RobotWorks
      @RobotWorks 2 ปีที่แล้ว

      I typed the code multiple times on different versions of eclipse but they all told me that there is an error why is that?

  • @tntalex28
    @tntalex28 2 ปีที่แล้ว

    :)