SlideShare a Scribd company logo
1 of 11
Download to read offline
import java.awt.*;
import java.applet.Applet;
public class mOVERH extends Applet implements Runnable{
Thread hilo= null;
int tiempoactual=200,co=1,ct;
HiloMover pelota1,pelota2,pelota3,pelota4,pelota5;
public void init(){ // x y tmp vel color
pelota1 = new HiloMover ("1",100,500,200,15,Color.GREEN,35);
pelota2 = new HiloMover ("2",200,200,200,10,Color.BLUE,70);
pelota3 = new HiloMover ("3",500,100,200,10,Color.RED,50);
pelota4 = new HiloMover ("4",50,600,200,10,Color.yellow,50);
pelota5 = new HiloMover ("5",350,10,200,10,Color.CYAN,50);
pelota1.cont=0;
pelota1.start();
pelota2.start();
pelota3.start();
pelota4.start();
pelota5.start();
}
public boolean action ( Event evt, Object obj)
{
return true;
}
public void paint(Graphics g)
{
this.setSize(850, 600);
//pelota 1
if(co != 5){
g.setColor(pelota1.color);
}else{
g.setColor(Color.BLACK);
}
g.fillOval(pelota1.xh,pelota1.yh, pelota1.tam,pelota1.tam);
//pelota 2
if(pelota1.cont>=3){
if(pelota2.cont==-1){
pelota2.cont=0;
co++;
}
if(co != 5){
g.setColor(pelota2.color);
}else{
g.setColor(Color.BLACK);
}
g.fillOval(pelota2.xh,pelota2.yh, pelota2.tam,pelota2.tam);
}
//pelota 3
if(pelota1.cont+pelota2.cont>=6){
if(pelota3.cont==-1){
pelota3.cont=0;
co++;
}
if(co != 5){
g.setColor(pelota3.color);
}else{
g.setColor(Color.BLACK);
}
g.fillOval(pelota3.xh,pelota3.yh, pelota3.tam,pelota3.tam);
}
//pelota 4
if(pelota1.cont+pelota2.cont+pelota3.cont >=9){
if(pelota4.cont == -1){
pelota4.cont = 0;
co++;
}
if(co != 5){
g.setColor(pelota4.color);
}else{
g.setColor(Color.BLACK);
}
g.fillOval(pelota4.xh,pelota4.yh, pelota4.tam,pelota4.tam);
}
//pelota 5
if(pelota1.cont+pelota2.cont+pelota3.cont+pelota4.cont >=12){
if(pelota5.cont == -1){
pelota5.cont = 0;
co++;
}
if(co != 5){
g.setColor(pelota5.color);
}else{
g.setColor(Color.black);
}
g.fillOval(pelota5.xh,pelota5.yh, pelota5.tam,pelota5.tam);
}
}
public void start() {
if (hilo==null) {
hilo = new Thread(this);
hilo.start();
}
}
public void run() {
while (hilo!=null && hilo.isAlive())
{
try {
hilo.sleep(tiempoactual);
}
catch (InterruptedException e) {} // No hacemos nada
repaint(); // Llama al paint()
}
}
public void stop() {
hilo = null;
}
}
import java.awt.Color;
public class HiloMover extends Thread{
int sleepTime,xh,yh,vel,tam;
int banx=0, bany=0,cont=-1;
Color color;
public HiloMover (String id, int x,int y, int tiempo, int velocidad, Color gc, int tamaño)
{
super (id);
// dormir entre o y 5 segundos
sleepTime = tiempo; //(int)(Math.random()*5000);
xh=x;
yh=y;
vel = velocidad;
color= gc;
tam = tamaño;
}
// ejecutar hilo
public void run()
{
int x=1; // poner el hilo a dormir durante un intervalo aleatorio
while (x ==1) // while (hilo!=null && hilo.isAlive())
{
try{
sleep(sleepTime);
}
catch(InterruptedException exception){
System.err.println("Excepción: " + exception.toString());
}
if (banx ==0)
xh=xh+vel;
else
xh=xh-vel;
if (bany ==0)
yh=yh-vel;
else
yh=yh+vel;
if (xh >800){
banx=1;
if(cont != -1)
cont++;
}
if (xh <=0){
banx=0;
if(cont != -1)
cont++;
}
if (yh <=0){
bany=1;
if(cont != -1)
cont++;
}
if (yh >550){
bany=0;
if(cont != -1)
cont++;
}
}
}
}
programa pelotas java
programa pelotas java
programa pelotas java
programa pelotas java

More Related Content

More from Anel Sosa

Metodologia incremental
Metodologia incrementalMetodologia incremental
Metodologia incrementalAnel Sosa
 
Paradigmas de programacion
Paradigmas de programacion Paradigmas de programacion
Paradigmas de programacion Anel Sosa
 
Escenario socioeconomico
Escenario socioeconomicoEscenario socioeconomico
Escenario socioeconomicoAnel Sosa
 
Investigacion calculo derivadas e integrales
Investigacion calculo derivadas e integralesInvestigacion calculo derivadas e integrales
Investigacion calculo derivadas e integralesAnel Sosa
 
Lenguajes de simulacion
Lenguajes de simulacionLenguajes de simulacion
Lenguajes de simulacionAnel Sosa
 
maquinas de turing jflap
maquinas de turing jflapmaquinas de turing jflap
maquinas de turing jflapAnel Sosa
 
Panuco Veracruz
Panuco Veracruz Panuco Veracruz
Panuco Veracruz Anel Sosa
 
que es un Curriculum
que es un Curriculumque es un Curriculum
que es un CurriculumAnel Sosa
 
maquinas de turing
maquinas de turingmaquinas de turing
maquinas de turingAnel Sosa
 
automatas finitos
 automatas finitos automatas finitos
automatas finitosAnel Sosa
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regularesAnel Sosa
 
ESPRESIONES REGULARES
ESPRESIONES REGULARESESPRESIONES REGULARES
ESPRESIONES REGULARESAnel Sosa
 
investigacion introduccion a los lenguajes y automatas
investigacion introduccion a los lenguajes y automatasinvestigacion introduccion a los lenguajes y automatas
investigacion introduccion a los lenguajes y automatasAnel Sosa
 
dibujo jigglypuff en java
dibujo jigglypuff en java dibujo jigglypuff en java
dibujo jigglypuff en java Anel Sosa
 
Programacion concurrente
Programacion concurrenteProgramacion concurrente
Programacion concurrenteAnel Sosa
 
Programa en java circulos
Programa en java circulosPrograma en java circulos
Programa en java circulosAnel Sosa
 
investigacion topicos avanzados de programacion unidad dos interfaz grafica
investigacion topicos avanzados de programacion unidad dos interfaz graficainvestigacion topicos avanzados de programacion unidad dos interfaz grafica
investigacion topicos avanzados de programacion unidad dos interfaz graficaAnel Sosa
 
DIBUJO EN JFRAME CASA
DIBUJO EN JFRAME CASADIBUJO EN JFRAME CASA
DIBUJO EN JFRAME CASAAnel Sosa
 
investigacion unidad tres componentes y librerias
investigacion unidad tres componentes y libreriasinvestigacion unidad tres componentes y librerias
investigacion unidad tres componentes y libreriasAnel Sosa
 

More from Anel Sosa (20)

SIMMAN 3G
SIMMAN 3GSIMMAN 3G
SIMMAN 3G
 
Metodologia incremental
Metodologia incrementalMetodologia incremental
Metodologia incremental
 
Paradigmas de programacion
Paradigmas de programacion Paradigmas de programacion
Paradigmas de programacion
 
Escenario socioeconomico
Escenario socioeconomicoEscenario socioeconomico
Escenario socioeconomico
 
Investigacion calculo derivadas e integrales
Investigacion calculo derivadas e integralesInvestigacion calculo derivadas e integrales
Investigacion calculo derivadas e integrales
 
Lenguajes de simulacion
Lenguajes de simulacionLenguajes de simulacion
Lenguajes de simulacion
 
maquinas de turing jflap
maquinas de turing jflapmaquinas de turing jflap
maquinas de turing jflap
 
Panuco Veracruz
Panuco Veracruz Panuco Veracruz
Panuco Veracruz
 
que es un Curriculum
que es un Curriculumque es un Curriculum
que es un Curriculum
 
maquinas de turing
maquinas de turingmaquinas de turing
maquinas de turing
 
automatas finitos
 automatas finitos automatas finitos
automatas finitos
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regulares
 
ESPRESIONES REGULARES
ESPRESIONES REGULARESESPRESIONES REGULARES
ESPRESIONES REGULARES
 
investigacion introduccion a los lenguajes y automatas
investigacion introduccion a los lenguajes y automatasinvestigacion introduccion a los lenguajes y automatas
investigacion introduccion a los lenguajes y automatas
 
dibujo jigglypuff en java
dibujo jigglypuff en java dibujo jigglypuff en java
dibujo jigglypuff en java
 
Programacion concurrente
Programacion concurrenteProgramacion concurrente
Programacion concurrente
 
Programa en java circulos
Programa en java circulosPrograma en java circulos
Programa en java circulos
 
investigacion topicos avanzados de programacion unidad dos interfaz grafica
investigacion topicos avanzados de programacion unidad dos interfaz graficainvestigacion topicos avanzados de programacion unidad dos interfaz grafica
investigacion topicos avanzados de programacion unidad dos interfaz grafica
 
DIBUJO EN JFRAME CASA
DIBUJO EN JFRAME CASADIBUJO EN JFRAME CASA
DIBUJO EN JFRAME CASA
 
investigacion unidad tres componentes y librerias
investigacion unidad tres componentes y libreriasinvestigacion unidad tres componentes y librerias
investigacion unidad tres componentes y librerias
 

programa pelotas java

  • 1. import java.awt.*; import java.applet.Applet; public class mOVERH extends Applet implements Runnable{ Thread hilo= null; int tiempoactual=200,co=1,ct; HiloMover pelota1,pelota2,pelota3,pelota4,pelota5; public void init(){ // x y tmp vel color pelota1 = new HiloMover ("1",100,500,200,15,Color.GREEN,35); pelota2 = new HiloMover ("2",200,200,200,10,Color.BLUE,70); pelota3 = new HiloMover ("3",500,100,200,10,Color.RED,50); pelota4 = new HiloMover ("4",50,600,200,10,Color.yellow,50); pelota5 = new HiloMover ("5",350,10,200,10,Color.CYAN,50); pelota1.cont=0; pelota1.start(); pelota2.start(); pelota3.start(); pelota4.start(); pelota5.start(); } public boolean action ( Event evt, Object obj) { return true; }
  • 2. public void paint(Graphics g) { this.setSize(850, 600); //pelota 1 if(co != 5){ g.setColor(pelota1.color); }else{ g.setColor(Color.BLACK); } g.fillOval(pelota1.xh,pelota1.yh, pelota1.tam,pelota1.tam); //pelota 2 if(pelota1.cont>=3){ if(pelota2.cont==-1){ pelota2.cont=0; co++; } if(co != 5){ g.setColor(pelota2.color); }else{ g.setColor(Color.BLACK); } g.fillOval(pelota2.xh,pelota2.yh, pelota2.tam,pelota2.tam); } //pelota 3 if(pelota1.cont+pelota2.cont>=6){ if(pelota3.cont==-1){
  • 3. pelota3.cont=0; co++; } if(co != 5){ g.setColor(pelota3.color); }else{ g.setColor(Color.BLACK); } g.fillOval(pelota3.xh,pelota3.yh, pelota3.tam,pelota3.tam); } //pelota 4 if(pelota1.cont+pelota2.cont+pelota3.cont >=9){ if(pelota4.cont == -1){ pelota4.cont = 0; co++; } if(co != 5){ g.setColor(pelota4.color); }else{ g.setColor(Color.BLACK); } g.fillOval(pelota4.xh,pelota4.yh, pelota4.tam,pelota4.tam); } //pelota 5 if(pelota1.cont+pelota2.cont+pelota3.cont+pelota4.cont >=12){ if(pelota5.cont == -1){ pelota5.cont = 0; co++; }
  • 4. if(co != 5){ g.setColor(pelota5.color); }else{ g.setColor(Color.black); } g.fillOval(pelota5.xh,pelota5.yh, pelota5.tam,pelota5.tam); } } public void start() { if (hilo==null) { hilo = new Thread(this); hilo.start(); } } public void run() { while (hilo!=null && hilo.isAlive()) { try { hilo.sleep(tiempoactual); } catch (InterruptedException e) {} // No hacemos nada repaint(); // Llama al paint() } } public void stop() { hilo = null; }
  • 5. } import java.awt.Color; public class HiloMover extends Thread{ int sleepTime,xh,yh,vel,tam; int banx=0, bany=0,cont=-1; Color color; public HiloMover (String id, int x,int y, int tiempo, int velocidad, Color gc, int tamaño) { super (id); // dormir entre o y 5 segundos sleepTime = tiempo; //(int)(Math.random()*5000); xh=x; yh=y; vel = velocidad; color= gc; tam = tamaño; } // ejecutar hilo public void run() { int x=1; // poner el hilo a dormir durante un intervalo aleatorio while (x ==1) // while (hilo!=null && hilo.isAlive()) { try{ sleep(sleepTime);
  • 6. } catch(InterruptedException exception){ System.err.println("Excepción: " + exception.toString()); } if (banx ==0) xh=xh+vel; else xh=xh-vel; if (bany ==0) yh=yh-vel; else yh=yh+vel; if (xh >800){ banx=1; if(cont != -1) cont++; } if (xh <=0){ banx=0; if(cont != -1) cont++; } if (yh <=0){ bany=1; if(cont != -1) cont++;
  • 7. } if (yh >550){ bany=0; if(cont != -1) cont++; } } } }