我正在为学校创建一个小应用程序,这会减少你输入jTextField的时间.我还没有那么远,因为当我创建Swing Timer时,我得到了一些我无法弄清楚的错误.我用Google搜索了运气.
这是我的代码.
package randomGUIs;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Timer extends javax.swing.JFrame {
String time;
Timer countDownTimer;
public Timer() {
initComponents();
ActionListener downTime = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
jLabel1.setText(time);
}
};
int countdown = 1000;
countDownTimer = new Timer(countdown, downTime);
countDownTimer.setRepeats(true);
};
Run Code Online (Sandbox Code Playgroud)
我得到的错误
错误:randomGUIs.Timer已在此编译单元中定义import javax.swing.Timer;
我正在使用Netbeans,并尝试取消选中"编译保存选项",但运气不错