Ajouter un commentaire

scoubida42
Re: Jeu de blackjack en java

ok, merci beaucoup pour votre aide!!!! mon blakcjack marche presque mais j'ai une erreur quand je veux faire l'affichage des cartes, le seul problème c'est que l'erreur je ne l'ai aps tout le temps et je ne comprends pas ce que c'est, d'où elle vient et donc je ne sais pas trop comment faire pour la corriger!!!

Voici mon code :
l'erreur se trouve à cette ligne là :
BufferedImage im = ImageIO.read(getClass().getResource(source));

Voici mon fichier entier pour l'affichage des cartes :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 */
public class computergraphicsPanel extends JPanel{


        //##############################################################################
    public graphicsGUI game;   //saves the current BlackjackGui instance on this variable so it can be reffered to in this class

    Graphics2D g2;

    public computergraphicsPanel(graphicsGUI b) {
        super();
        game = b; //creates a new game called b
}

        public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g2 = (Graphics2D) g;
        draw(g2);
    }

           //  !--- All the drawing is done in this method ---!
    public void draw(Graphics2D g2) {
        Boolean turnCard1=game.turnCard;
        Hand computerHand = game.getComputerHand();
        int xPosition = 10; //starting x coordinate which gets larger to shift the additional cards accross
        int numberOfCards = computerHand.getSize();
        for (int i = 0; i < numberOfCards; i++) {

            if (i == 0 && turnCard1==false) {    //draw the dealers cards and check if first card should be faceup or facedown

                try {
                    BufferedImage im = ImageIO.read(getClass().getResource("/graphics/images/back-blue-75-1.png"));    //while the first card should be facedown, draw a facdown card

                    g2.drawImage(im, xPosition, 20, this);  //draws the card im at those coordinates

                    xPosition = xPosition + 100;    //shifts the next card over to the right by 40 pixels

                } catch (IOException ex) {
                     Logger.getLogger(humangraphicsPanel.class.getName()).log(Level.SEVERE, null, ex);

                }

            }
            else {

                Card currentCard = computerHand.getCard(i);
                String source = currentCard.getImage();

                try {
                    BufferedImage im = ImageIO.read(getClass().getResource(source));
                    g2.drawImage(im, xPosition, 20, this);
                    xPosition = xPosition + 100;

                } catch (IOException ex) {
                    Logger.getLogger(humangraphicsPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        repaint();
        game.repaint();
    }
}

Voici l'erreur :

Exception occurred during event dispatching:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1362)
at graphics.computergraphicsPanel.draw(computergraphicsPanel.java:72)
at graphics.computergraphicsPanel.paintComponent(computergraphicsPanel.java:40)

Merci de votre aide pour corriger cette erreur, où juste me dire ce qu'il faut que je fasse ce serait super gentil:!!!merci beaucoup par avance!!!

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 U   U   QQQ    U   U  N   N   GGG  
U U Q Q U U NN N G
U U Q Q U U N N N G GG
U U Q QQ U U N NN G G
UUU QQQQ UUU N N GGG
Q