Problems with String.format()
-
Good afternoon. I use the old version of JAVA, 1.4.2.
The program used a thing like String.format(). But when attempting to compile, it makes a mistake of the species.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));
Question is whether there are any alternatives to String.format(s) for JAVA 1.4. 2?
Programme code itselfimport 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);
}
♪
-
tl.this.setText(String.format("%02d:%02d", (int) t / 60, (int) t % 60));