Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please help me with my Java Countdown Timer

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Please help me with my Java Countdown Timer

    Hello generous java coders!I am really in a desperate situation now. I have a working gui code here:

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class CountdownTimer extends JFrame  {
     
        JLabel promptLabel, timerLabel;
        int counter;
        JTextField tf;
        JButton button;
        Timer timer;
     
        public CountdownTimer() {
            setLayout(new GridLayout(2, 2, 5, 5));
            promptLabel = new JLabel("Enter time: ", SwingConstants.CENTER);
            add(promptLabel);
     
            tf = new JTextField(5);
            add(tf);
     
            button = new JButton("Start timing");
            add(button);
     
            timerLabel = new JLabel("Waiting...", SwingConstants.CENTER);
            add(timerLabel);
     
            event e =  new event();
            button.addActionListener(e);
     
     
        }
     
     
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
     
        public void run() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public class event implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                int count = (int)(Double.parseDouble(tf.getText()));
                timerLabel.setText("Time left: " + count);
     
                TimeClass tc = new TimeClass(count);
                timer = new Timer(1000, tc);
                timer.start();
     
            }
        }
     
        public class TimeClass implements ActionListener {
            int counter;
     
            public TimeClass(int counter) {
                this.counter= counter;
     
       }
            public void actionPerformed(ActionEvent tc) {
                counter--;
     
                if(counter >= 1) {
                    timerLabel.setText("Time left: " + counter);
     
                }
                else {
                    timer.stop();
                    timerLabel.setText("Done!");
                    Toolkit.getDefaultToolkit().beep();
     
                }
            }
        }
        public static void main(String args[]) {
            CountdownTimer gui = new CountdownTimer();
            gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gui.setSize(250, 100);
            gui.setTitle("Timer Program");
            gui.setVisible(true);
     
        }
     
    }

    My task is to make a gui countdown timer for a speech contest. Please help me convert it into a gui wherein when the user creates a new "session". User should be able to input the speaker's name, duration of speech(this is where the code above comes in. The code I have pasted above is only a Second Timer please help me convert it into a Minute timer as well. example: 7:00 -> 6:59 -> 6:58 so on and so forth), the speech title and a drop down box with two values: formal speech/table topics). Lastly, user should also be able to save time to a file. I am really desperate for you help guys. Please do help me Please please


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me with my Java Countdown Timer

    What would the user input for a minute timer?
    Then how would that value be saved and displayed?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my Java Countdown Timer

    Quote Originally Posted by Norm View Post
    What would the user input for a minute timer?
    Then how would that value be saved and displayed?
    Hello, thank you so much for your response. The user should be able to input the name of the speaker, the speech duration,title of the speech and a drop down box these inputs should be saved into a file. Thank you!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me with my Java Countdown Timer

    What happened to the input and display of the time?

    For the other stuff, take a look at how to write a Swing GUI:
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    And how to write to files:
    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to Use Timer in Java
    By neo_2010 in forum Java SE API Tutorials
    Replies: 2
    Last Post: August 6th, 2013, 09:49 AM
  2. [SOLVED] Countdown type game help needed.
    By Acaul in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 14th, 2012, 10:55 AM
  3. Timer Countdown - Code Syntax
    By baddack in forum What's Wrong With My Code?
    Replies: 22
    Last Post: September 26th, 2012, 03:56 PM
  4. Timer class countdown
    By p0oint in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2010, 03:31 AM
  5. How to Use Timer in Java
    By neo_2010 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: September 1st, 2009, 12:10 PM

Tags for this Thread