why is my java.awt.Window not repainting after I called the repaint() method?
public class Counter extends Window implements ActionListener {
private static final long serialVersionUID = 1L;
private Timer timer;
private int time;
public Counter() {
super(null);
setAlwaysOnTop(true);
setBounds(getGraphicsConfiguration().getBounds());
setBackground(new Color(0, true));
setVisible(true);
timer = new Timer(1000, this);
timer.start();
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.clearRect(0, 0, getWidth(), getHeight());
g.setColor(Color.RED);
g.drawString(String.valueOf(time), getWidth()/2, getHeight()/2);
}
@Override
public void update(Graphics g) {
super.update(g);
}
@Override
public void actionPerformed(ActionEvent e) {
time++;
repaint();
}
As you can see i created a timer with a delay of 1 second. After that i call repaint() to draw the counter's number on the screen. But it only draws a zero on my screen and stops drawing then (the zero stays on screen). First i thought that the paint method is only called once, but i tested a System.out.prinln() and prooved that the paint method is executed every second so it should actually repaint the window... So i don't know where i made a mistake.
And yes it is my intention to use the awt.Window and not a JFrame or Frame etc..