Foros del Web » Programación para mayores de 30 ;) » Java »

Error al poner icono en java a un jlabel

Estas en el tema de Error al poner icono en java a un jlabel en el foro de Java en Foros del Web. bueno lo que ma pasa es que yo le do un icono a un jlabel (es un personaje, de un juego, que a sido ovido ...
  #1 (permalink)  
Antiguo 27/04/2015, 16:36
 
Fecha de Ingreso: abril-2015
Mensajes: 1
Antigüedad: 8 años, 11 meses
Puntos: 0
Exclamación Error al poner icono en java a un jlabel

bueno lo que ma pasa es que yo le do un icono a un jlabel (es un personaje, de un juego, que a sido ovido con las teclas), bueno cuando llamo al metodo donde se le cambia el icono el icono se pone donde estaba inicialmente el jlabel, como si jamas lo hubiese movido con las teclas y puedo eso me esta jodiendo la vida como lo arreglo

codigo:

//CLASE DONDE SE LLAMA EL METODO SOLO VAYAN A DONDE DICEN LOS //COMENTARIOS




CLASE CON EL METODO CON EL ERROR
HAY OTRA CLASE PERO ESA CLASE SOLO LLAMA AL METODO "TECLADO"



Código Java:
Ver original
  1. package killthegamsters.Codigo;
  2.  
  3. import java.util.Vector;
  4. import javax.swing.ImageIcon;
  5. import killthegamsters.Ventanas.Complementos;
  6. import killthegamsters.Ventanas.Juego;
  7. import static killthegamsters.Ventanas.Juego.Kevin;
  8.  
  9.  
  10. public class Protagonista extends Personajes{
  11.    
  12.     Vector<ImageIcon> ima = new Vector<ImageIcon>();
  13.    
  14.  
  15.    
  16.     private static int nivel = 0;
  17.  
  18.    
  19.     //SETTER AND GETTER
  20.    
  21.     public int getNivel() {
  22.         return nivel;
  23.     }
  24.  
  25.     public void setNivel(int nivel) {
  26.         Protagonista.nivel = nivel;
  27.     }
  28.    
  29.        
  30.    
  31.     //CONSTRUCTOR
  32.    
  33.     public Protagonista(){
  34.         }
  35.    
  36.     public static void Hola(){
  37.         System.out.println("hola baka");
  38.     }
  39.    
  40.     //METODOS
  41.     public void MoverDerecha(Protagonista prota, Enemigo e,Complementos com,EsperarDisparo es){
  42.             if(Juego.Kevin.getX() < 500){
  43.             Juego.Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/adi.gif")));
  44.             prota.x += 2;
  45.             Juego.Kevin.setLocation(x, y);  
  46.             prota.direccion = true;      
  47.             }else{
  48.                         Juego.Kevin.setLocation(3, prota.y);
  49.                         Juego.Fondo.setIcon(ima.elementAt(nivel));
  50.                         e.valor(e,es);
  51.                         prota.valor(prota, com);
  52.                         Juego.Rata.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/paradoi.png")));
  53.                         prota.setNivel(prota.getNivel() + 1);
  54.             }  
  55.             }      
  56.                
  57.                
  58.                
  59.            
  60.     public void Agachar(){  //ERROR
  61.        Juego.Kevin.setLocation(x, y);
  62.         Juego.Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/AgachadoD.png")));      
  63.         Juego.Kevin.setLocation(x, y);
  64.     }                
  65.    
  66.    
  67.     public void MoverIzquierda(Protagonista prota){
  68.             Juego.Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/aii.gif")));
  69.             prota.x -= 2;
  70.             Juego.Kevin.setLocation(x, y);  
  71.             prota.direccion = false;
  72.     }
  73.    
  74.     public void valor(Protagonista prota, Complementos comple){
  75.         prota.ima.add( new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/1_1.jpg")));
  76.         prota.ima.add( new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/2.jpg")));
  77.         prota.ima.add( new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/3.jpg")));
  78.         prota.ima.add( new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/4.jpg")));    
  79.         prota.setDireccion(true);
  80.         prota.setNombre(comple.getRNombre());
  81.         prota.setPedido(false);
  82.         prota.setVida(100);
  83.         prota.setX(Juego.Kevin.getX());
  84.         prota.setY(Juego.Kevin.getY());
  85.         Juego.HP.setValue(prota.getVida());
  86.         Juego.vida.setText("HP: "+prota.getVida()+"/100");
  87.         Juego.Rango.setText(prota.getNombre()+": Cadete");
  88.     }
  89.    
  90.     public void DisparoBien(Enemigo ene, Protagonista prota,java.awt.event.MouseEvent evt ){
  91.         bala.play();
  92.             if(prota.getDireccion() && prota.getX() < ene.getX()){
  93.             if(ene.getVida() > 0 && prota.getVida() > 0){
  94.             if(ene.getVida() > 1){
  95.                Daño.play();
  96.                 Juego.Rata.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/sangrei.png")));
  97.                 ene.setVida(ene.getVida() - 1);
  98.             }else{
  99.                 Daño.play();
  100.                 Juego.Rata.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/si.gif")));
  101.                 ene.setVida(ene.getVida() - 1);
  102.                 }
  103.    
  104.             }
  105.     }
  106.             }
  107.    
  108.     public void Teclado(Protagonista prota,java.awt.event.KeyEvent evt,Enemigo e,Complementos com, Esperar es,EsperarDisparo espe){
  109.           if(evt.getKeyChar() == 'a'){
  110.               prota.MoverIzquierda(prota);
  111.           }
  112.           if(evt.getKeyChar() == 'd'){
  113.               prota.MoverDerecha(prota,e,com,espe);
  114.           }
  115.           if(evt.getKeyChar() == 'w'){
  116.               prota.Salto(prota,es,com);
  117.           }
  118.           if(evt.getKeyChar() == 's'){
  119.               prota.Agachar(); //METODO CON EL ERROR
  120.           }
  121.  
  122.        
  123.     }
  124.     public void detenerce(java.awt.event.KeyEvent evt, Protagonista prota, Esperar es, Complementos com){
  125.         if(evt.getKeyChar() == 'd'){
  126.             Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/PoliciaD.png")));
  127.         }
  128.         if(evt.getKeyChar() == 'a'){
  129.             Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/PoliciaI.png")));
  130.         }
  131.         if(evt.getKeyChar() == 'w'){
  132.             prota.BajarS(prota,es,com);
  133.         }
  134.         if(evt.getKeyChar()== 's'){
  135.             Juego.Kevin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/killthegamsters/Texturas/PoliciaD.png")));
  136.     }
  137.     }
  138.     public void DisparoFail(){
  139.         bala.play();
  140.     }
  141.     public void Salto(Protagonista prota, Esperar es,Complementos com){
  142.         if(Juego.Kevin.getY() > 120){
  143.             prota.y--;
  144.             Juego.Kevin.setLocation(prota.getX(), prota.getY());
  145.         }else{
  146.             prota.BajarS(prota,es, com );
  147.            
  148.         }
  149.     }
  150.     public void BajarS(Protagonista prota, Esperar esperar, Complementos com ){
  151.         try {
  152.         esperar.start();    
  153.         } catch (Exception e) {
  154.         }
  155.        
  156.      
  157.         }
  158.        
  159.  
  160.  
  161. }

Etiquetas: icono, problemita
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:26.