//Codigo fuente applet: Botones import java.applet.Applet; import java.awt.*; public class Botones extends Applet { Button b1,b2,b3,b4; int a=100; int b=100; Image flechas[] = new Image[5]; Image flecha; // Creamos cuatro botones normales, push-button public void init() { b1 = new Button( "< <<<<< <" ); b2 = new Button( "Botón Subir" ); b3 = new Button( "> >>>>> >" ); b4 = new Button( "Botón Abajo" ); // Panel p = new Panel(); // p.add( b1 ); // p.add( b2 ); // add( "South",p ); this.add(b1); this.add(b2); this.add( b3 ); this.add( b4 ); // String flechassrc[]={"Izquierda.gif","Arriba.gif","Derecha.gif","Abajo.gif"}; // for (int i=0;i< flechas.length;i++){ // flechas[i] = getImage(getCodeBase(),"" + flechasscr[i]);} flechas[1]= getImage(getCodeBase(),"Izquierda.gif"); flechas[2]= getImage(getCodeBase(),"Arriba.gif"); flechas[3]= getImage(getCodeBase(),"Derecha.gif"); flechas[4]= getImage(getCodeBase(),"Abajo.gif"); flecha= getImage(getCodeBase(),"X.gif"); } public void paint(Graphics g) { g.setColor(Color.blue); g.fillRect(a,b,30,30); g.drawImage(flecha,a,b,this); } // Comprobamos cuando llega un evento, cual ha sido el boton que // lo ha generado, e imprimimos un mensaje en la pantalla public boolean action( Event evt,Object obj ) { if( evt.target.equals( b1 ) ){ a=a-10; if (a<0){a=a+10;}; flecha=flechas[1]; repaint(); } if( evt.target.equals( b2 ) ){ b= b-10; if (b<0){b=b+10;}; flecha=flechas[2]; repaint(); } if( evt.target.equals( b3 ) ){ a=a+10; flecha=flechas[3]; if (a>200) {a=a-10;} repaint(); } if( evt.target.equals( b4 ) ){ b= b+10; if (b>200){b=b-10;}; flecha=flechas[4]; repaint(); } return true; } } //------------------------------------------ Final del fichero Botones.java