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

        tf = new JTextField(5);

        button = new JButton("Start timing");

        timerLabel = new JLabel("Waiting...", SwingConstants.CENTER);

        event e =  new event();


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


    public class TimeClass implements ActionListener {
        int counter;

        public TimeClass(int counter) {
            this.counter= counter;

        public void actionPerformed(ActionEvent tc) {

            if(counter >= 1) {
                timerLabel.setText("Time left: " + counter);

            else {

    public static void main(String args[]) {
        CountdownTimer gui = new CountdownTimer();
        gui.setSize(250, 100);
        gui.setTitle("Timer Program");



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

Recommended Answers

All 4 Replies

ehm ... who wrote the above code?
if you did, you managed to figure out how to create a Timer for one second. adjust that to one minute.
that would be step 1.

Hi there, thank you very much for the reply. I tried to convert it by changing

            timer = new Timer(1000, tc);

in line 49 to

            timer = new Timer(6000, tc);

since 1 minute is equal to 60 000 milliseconds.
I also changed the output of the gui so it can display both minute and second part. I've managed to make the "minute" part work. My gui's output is something like this:


then it becomes:


How do I do the "second part"?

Thank you very much.

Get count in seconds as it was earlier.

 timer = new Timer(1000, tc);

then divide it by 60 and show then display remainer as in seconds and quotient as minutes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.