0

タイマーを使用して JLabel を更新する際にまだ問題があります。私は何が欠けているのか理解できないようです。グローバル秒変数はゼロのままなので、タイマーは機能していると思いますが、GUI ウィンドウは更新されませんか?

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

class Globals 
{
    public static int seconds = 0;
}

class main
{
    public static void main(String Args[])
    {

        //text timeline = new text();
        JFrame testing = new JFrame();
        frame textdes = new frame();
        testing.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        testing.setSize(1000,1000);
        testing.setVisible(true);

        Countdown timer = new Countdown();
        Timer countdown = new Timer(5000, timer);
        countdown.start();

        JLabel countdowntext = new JLabel();
        countdowntext.setText("Now its :" + Globals.seconds);
        testing.add(countdowntext);     
        testing.add(textdes);

    }
}

class frame extends JFrame
{
    class Countdown implements ActionListener 
    {
        public void actionPerformed(ActionEvent e)
        {
            Globals.seconds++;
        }
    }
}
4

2 に答える 2