내 프로젝트의 타이머 기반 응용 프로그램을 디자인하려고합니다 (온라인 테스트). 남은 시간을 레이블에 표시해야했습니다. 그래서 String.format을 사용하고있었습니다. 그러나 이클립스가 오류가 있다고 보여줍니다,타이머 응용 프로그램의 인수에 String.format이 적용되지 않습니다.
The method format(String, Object[]) in the type String is not applicable for the arguments (String, int)).
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Formatter;
import javax.swing.*;
public class RadioButton {
JFrame frame=new JFrame("RadioRadio");
JLabel timerl = new JLabel("Press Button to start");
JPanel butp = new JPanel();
JButton button = new JButton("Start Exam");
Timer mytimer;
String ss="Time Remaining %02d Seconds!";
int elapsedSeconds = 0;
int total=10;
public void radioButton()
{
frame.setSize(300,300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(butp);
butp.add(button);
butp.add(timerl);
frame.setVisible(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (mytimer != null && mytimer.isRunning()) {
mytimer.stop();
mytimer = null;
timerl.setText("Exam Terminated");
} else {
mytimer = new Timer(1000, new TimerListener());
mytimer.start();
String t = String.format(ss, total);
timerl.setText(t);
}
}
});
}
private class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
elapsedSeconds++;
if (elapsedSeconds == total) {
mytimer.stop();
timerl.setText("Time Up");
} else {
String t = String.format(ss, total - elapsedSeconds);
timerl.setText(t);
}
}
}
public static void main(String args[])
{
RadioButton r=new RadioButton();
r.radioButton();
}
}
나에게 좋은 것 같다 대해 이야기하지 마십시오 잘 컴파일 잘 실행 ... – MadProgrammer
에는 컴파일 오류가 없습니다 'javac'와 함께 –
정확히 내 편이 컸다. –