For a few days now I have been working on a Timer
program in Java.
How it works is, you open the program and the JLabel
counts up. For some reason it doesn't repeat itself and only works once.
Here's my code.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.SwingConstants;
import java.awt.Font;
public class TimerC extends JFrame implements ActionListener{
Timer t = new Timer(5, this);
public int intClicked;
public String stringClicked;
public JLabel clicked;
public TimerC() {
t.start();
JPanel p1 = new JPanel();
getContentPane().add(p1);
p1.setLayout(null);
JLabel clicked = new JLabel();
clicked.setFont(new Font("Tahoma", Font.PLAIN, 64));
clicked.setHorizontalAlignment(SwingConstants.CENTER);
clicked.setText("0");
int intClicked = 1;
String stringClicked = String.valueOf(intClicked);
clicked.setText(stringClicked);
p1.add(clicked);
clicked.setSize(42, 100);
clicked.setLocation(191, 97);
}
@Override
public void actionPerformed(ActionEvent e) {
}
}