import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;

/**
 * Class Timer1 - 
 * 
 * @author smh 
 * @version 1
 * @date 2011-03-14
 */
public class Timer1 extends JApplet
{
    private int x= 0, y= 0;
    private int xsize = 15, ysize = 15;
    private int screenWidth, screenHeight;
    private Random gen = new Random();
    Timer timer = new Timer(1000, new TimerListener());

    
    public void init()
    {
        //JRootPane rootPane = this.getRootPane();    
        //rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
    
        screenWidth = getWidth();
        screenHeight = getHeight();
        setBackground(Color.blue);
        
        timer.start();
        
    }

    public void start()
    {   }

 
    public void stop()
    {   }

 
    public void paint(Graphics g)
    {
        
        g.drawString("screenWidth: " + screenWidth, 10, 10);
        
        g.clearRect(x, y, xsize, ysize);
        x = gen.nextInt(screenWidth - xsize);
        y = gen.nextInt(screenHeight - ysize);
      
        g.fillRect(x, y, xsize, ysize);
    }

 
    public void destroy()
    {    }

    
    class TimerListener implements ActionListener {
        
        public void actionPerformed(ActionEvent e) {
            repaint();                                  // --> paint()
        }
    }
}