So, this code is giving me some errors, any idea?

private void pintarMobs()
    {
        JButton boton = null;


        Component[] botones = pnCastillo.getComponents();
        for (Component c: botones){


            boton = (JButton) c;
            int ac = Integer.parseInt(boton.getActionCommand());
            int a = 0;
            Random r = new Random();
            String foto = null;

            if( ac != 0){
                if (ac == 6)
                    foto = "/img/ghostking.png";

                else if (ac == 1)
                    foto = "/img/busters.png";

                else     
                    a = r.nextInt(8-1) + 1;

                    if(a==1)
                        foto = "/img/ghost1.png";
                    else if(a==2)
                        foto = "/img/ghost2.png";
                    else if(a==3)
                        foto = "/img/ghost3.png";
                    else if(a==4)
                        foto = "/img/ghost4.png";
                    else if(a==5)
                        foto = "/img/ghost5.png";
                    else if(a==6)
                        foto = "/img/ghost6.png";
                    else if(a==7)
                        foto = "/img/ghost7.png";
                    else if(a==8)
                        foto = "/img/ghost8.png";

            }
            boton.setIcon(new ImageIcon(getClass().getResource(foto)));
        }
    }

"giving me some errors" tells us nothing. If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.