/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Examen.bolita;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;

/**
 *
 * @author felix
 */
public class Dibujar extends JPanel{
    private bolita miBola;
    private MueveBolita mueve;
    
    public Dibujar() {
        miBola = new bolita();
        this.setPreferredSize(new Dimension(400, 400)); // Tamanio del lienzo
        this.setBackground(Color.WHITE); // Pone un color de fondo
        this.setVisible(true);
        mueve = new MueveBolita();
        mueve.start();
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        miBola.dibuja(g);
    }
    
    private class MueveBolita extends Thread {
        @Override
        public void run() {
            int i;
            while(true) {
                
                for(i=40; i<360; i++) {
                     miBola.mueve(40, i);
                    try {
                        sleep(10);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Dibujar.class.getName()).log(Level.SEVERE, null, ex);
                    }
                     repaint();
                }

                for(i=360; i>40; i--){
                    miBola.mueve(40, i);
                    try {
                        sleep(10);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Dibujar.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    repaint();
                }
                
                
                try {
                    sleep(10);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Dibujar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    
    }

}
