package def;

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

import java.util.Random;

/**
 * Class Timer1 - 
 * 
 * @author smh 
 * @version 2
 * @date 11/19/2013
 * 
 */
public class Timer1 extends JFrame
{

   	Timer timer;
	int x= 0, y= 0;
	int xsize = 15, ysize = 15;
	int screenWidth = getWidth();
	int screenHeight = getHeight();
	Graphics graphics;
	
	public Timer1() {

		x= 0;
		y= 0;
    	xsize = 15;
    	ysize = 15;

    	timer = new Timer(1000, new ActionListener() {
    	   public void actionPerformed(ActionEvent ev) {
    		repaint();
    	}});
    	
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    	DrawPanel drawPanel = new DrawPanel();
    	getContentPane().setBackground(Color.blue);
    	graphics = getContentPane().getGraphics();
    	
    	add(drawPanel, BorderLayout.CENTER);
 
    	JPanel buttonPanel = new JPanel();
    	buttonPanel.setBackground(Color.red);
    	
    	JButton button = new JButton("start");
    	button.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent ev) {
    			timer.start();
    		}
    	});
    	buttonPanel.add(button);
    	
    	JButton button1 = new JButton("stop");
    	button1.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent ev) {
    			timer.stop();
    		}
    	});
    	buttonPanel.add(button1);
    	
    	add(buttonPanel, BorderLayout.SOUTH);
    	
    	}

    public static void main(String[] args) {
    	Timer1 gui = new Timer1();
 
    	gui.setSize(500, 500);
    	gui.setVisible(true);
    }

    
 public class DrawPanel extends JPanel {

    public void paintComponent(Graphics g)
    {
    	x = 0;
    	y = 0;

    	g.setColor(Color.black);
    	
        x = (int) (Math.floor(Math.random() * 450.0)); 
        y = (int) (Math.floor(Math.random() * 450.0));
        g.fillRect(x, y, xsize, ysize);
        
 //       System.out.println(x + " " + y + " " + xsize + " " + ysize + " ");
        
    }
 }
}
 
 


