Java GUI help? Image Class

Discussion in 'Programming' started by Xphic, Sep 27, 2009.

  1. #1
    Hey Guys,


    I am working on a BlackJack GUI, I have just about everything set up, and now I am working on generating the cards.


    I was doing some quick snippet test, to see if I can get it working. But no luck, I wanted to know if I can get some advice on this subject.

    Like which Image Class to use.

    
    public void createDealer()
    {
    		JPanel dealerPanel = new JPanel();
    		dealerPanel.setLayout(new GridLayout());
    		Image backCard = new Image();
    		JLabel dealerName = new JLabel("Dealer");
    		JLabel potAmt = new JLabel("Pot Amount: ");
    		
    		dealerPanel.add(dealerName);
    		dealerPanel.add(potAmt);		
    }
    
    Code (markup):
    This is what I am trying to do.

    This Card here:
    http://upload.wikimedia.org/wikipedia/commons/d/d3/Poker-sm-221-Ah.png

    I would call it AH.jpg

    I read the Java api, and I just dont know how to add it as an image, and then added it to the dealerPanel(or PlayerPanel), casting an image as a component seemed strange. I dont even know if that method would work.

    Any tips towards the correct direction would be great.
     
    Xphic, Sep 27, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    
    JLabel card = new JLabel(new ImageIcon(backCard));
    
    dealerPanel.add(card);
    
    Code (markup):
     
    caprichoso, Sep 28, 2009 IP