我正在尝试制作一个在我按下按钮但从不启动时执行的 Swing Timer。我的代码是:
public class prueba extends JFrame {
java.util.Date date= new java.util.Date();
private JPanel contentPane;
Timer timero;
........
public prueba() {
..........
timero = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("otra vez....uauuauauaua");
}
});
btnIniciar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
timero.start();
...............
请问你能帮帮我吗?谢谢和对不起我的英语!
当我这样做时,我有一个错误:
public class prueba extends JFrame {
java.util.Date date= new java.util.Date();
private JPanel contentPane;
Timer timero;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
prueba frame = new prueba();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public prueba() {
final WebManager web = new WebManager("user","pass","http://www.spanishtracker.com/login.php");
//web.EnableDebug();
web.doLogin();
web.getCookies;
.....
contentPane.add(txtSalida, gbc_txtSalida);
timero.start();
它给了我一个错误:
java.lang.NullPointerException
at prueba.<init>(prueba.java:216)
at prueba$1.run(prueba.java:56)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
These lines are:
216 timero.start();
56 prueba frame = new prueba();