You are on page 1of 10

/** * @(#)RatonApplet1.java * * * @author * @version 1.

00 2010/8/10 */

import java.awt.*; import java.awt.event.*; import java.applet.*;

public class RatonApplet1 extends Applet implements MouseListener { static Figura f1, f2,f3,f; static Figura1 ff; static Figura2 fi;

final Color[] colores={Color.white,Color.red, Color.green, Color.blue,Color.yellow}; static int indice,indice1,indice2,indice3,x,y,x1,y1,ancho,alto; int vg; String velocidadGiro;

Choice ch1 = new Choice(); Choice ch2 = new Choice(); Choice ch3 = new Choice(); Choice ch4 = new Choice(); private final int radio = 8;

public void init() { velocidadGiro = getParameter("fps"); vg = (velocidadGiro != null) ? Integer.parseInt(velocidadGiro) : 10; x1=0; y1=0; x=12; y=12;

ch1.addItem("COLOR"); ch1.addItem("Rojo"); ch1.addItem("Verde"); ch1.addItem("Azul"); ch1.addItem("Amarillo"); ch1.select(0);

ch1.setBounds(200, 570, 80, 20); ch2.addItem("FIGURA"); ch2.addItem("Cuadrado"); ch2.addItem("Circulo"); ch2.addItem("Ovalo"); ch2.setBounds(40, 610, 80, 20);

ch3.addItem("VELOCIDAD"); ch3.addItem("Lento"); ch3.addItem("Medio"); ch3.addItem("Rapido");

ch3.setBounds(60, 610, 80, 20);

ch4.addItem("TAMAO"); ch4.addItem("Pequeo"); ch4.addItem("Mediano"); ch4.addItem("Grande"); ch4.setBounds(80, 610, 80, 20);

/*

f1=new Figura(20, 20, 100, 100, vg, Color.YELLOW); f1.setSize(145,145); f1.start(); f2=new Figura(20, 20, 100, 100, vg*20, Color.RED); f2.setSize(145,145); f2.start();*/ add(ch1); add(ch2); add(ch3); add(ch4);

// //

add(f2); add(f1);

ch1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { ch1_itemStateChanged(e); } });

ch2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { ch2_itemStateChanged(e); } });

ch3.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { ch3_itemStateChanged(e); } }); ch4.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { ch4_itemStateChanged(e); } });

setBackground(Color.gray); addMouseListener(this);

public void mousePressed(MouseEvent ev) {

Graphics g = getGraphics(); //g.setColor(Color.green);

// g.fillOval(ev.getX()-radio, ev.getY()-radio, 2*radio, 2*radio); // g.drawOval(ev.getX()-radio, ev.getY()-radio, 2*radio, 2*radio);

// //

//color if(indice==0){

if(indice==1){

} if(indice==2){

/// velocidad if(indice2==1){ vg = (velocidadGiro != null) ? Integer.parseInt(velocidadGiro) : 10;

if(indice2==2){ vg = (velocidadGiro != null) ? Integer.parseInt(velocidadGiro) : 40;

} if(indice2==3){ vg = (velocidadGiro != null) ? Integer.parseInt(velocidadGiro) : 70;

} //tamao if(indice3==1){ ancho=25; alto=25; x1=50; y1=50; }

if(indice3==2){ ancho=45; alto=45;

x1=70; y1=70;

} if(indice3==3){ ancho=65; alto=65; x1=90; y1=90;

/*------------ f=new Figura(x, y, ancho, alto, vg, colores[indice]);

f.setSize(x1,y1); f.setLocation(ev.getX(),ev.getY()); f.start(); add(f);---------------*/

///figura if((indice1==1)&&(indice!=0)&&(indice2!=0)&&(indice3!=0)){ f=new Figura(x, y, ancho, alto, vg, colores[indice]);

f.setSize(x1,y1); f.setLocation(ev.getX(),ev.getY()); f.start(); add(f);

if((indice1==2)&&(indice!=0)&&(indice2!=0)&&(indice3!=0)){

ff=new Figura1(x, y, ancho, alto, vg, colores[indice]);

ff.setSize(x1,y1); ff.setLocation(ev.getX(),ev.getY()); ff.start(); add(ff);

} if((indice1==3)&&(indice!=0)&&(indice2!=0)&&(indice3!=0)){ fi=new Figura2(x, y, ancho, alto, vg, colores[indice]);

fi.setSize(x1,y1); fi.setLocation(ev.getX(),ev.getY()); fi.start(); add(fi);

g.dispose(); }

void ch1_itemStateChanged(ItemEvent e) { indice=ch1.getSelectedIndex();

void ch2_itemStateChanged(ItemEvent e) { indice1=ch2.getSelectedIndex();

void ch3_itemStateChanged(ItemEvent e) { indice2=ch3.getSelectedIndex();

} void ch4_itemStateChanged(ItemEvent e) { indice3=ch4.getSelectedIndex();

public void mouseExited(MouseEvent event) {} public void mouseReleased(MouseEvent event) {}

public void mouseClicked(MouseEvent event) {} public void mouseEntered(MouseEvent event) {}

You might also like