Good day. I use in the work the old version of JAVA namely 1.4.2
The program used such a thing as String.format (). But when trying to compile it gives the error
tl.java:25: cannot resolve symbol symbol : method format (java.lang.String,int,int) location: class java.lang.String tl.this.setText(String.format("%02d:%02d", t / 60, t % 60));
The question is - are there any alternatives to String.format () for JAVA 1.4.2?
The program code itself
import java.util.Timer; import java.util.TimerTask; import javax.swing.*; import java.awt.*; public class tl extends JLabel { public tl (Timer timer) { timer.scheduleAtFixedRate(timerTask, 0, 1000); } private TimerTask timerTask = new TimerTask() { private volatile int time = -1; private Runnable refresher = new Runnable() { public void run () { int t = time; tl.this.setText(String.format("%02d:%02d", t / 60, t % 60)); } }; public void run () { time++; SwingUtilities.invokeLater(refresher); } }; public static void main (String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel timerLabel = new tl(new Timer()); timerLabel.setFont(new Font(timerLabel.getFont().getFontName(), timerLabel.getFont().getStyle(), 36)); frame.add(timerLabel); frame.pack(); frame.setVisible(true); }
}