Incompattible type- just a quick question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Incompattible type- just a quick question

  1. #1
    Join Date
    Mar 2004
    Posts
    2

    Incompattible type- just a quick question

    If anyone can help me i'd be most grateful.

    I am trying to copy a value from one array into another.


    The part i am having problem with is:
    private Hand hand[][];
    private Card deck[];


    public void paint ( Graphics g )
    {
    for (int i=0; i<hand.length; i++)// player nums
    {
    //PlayerLabel.setText( "Player" );
    for (int j=0; j<hand[i].length; j++) //card nums
    {
    hand[i][j] = deck[L];
    Image image;
    image = Toolkit.getDefaultToolkit().getImage
    ( "cards/" + (deck[L]) + ".gif");
    g.drawString(String.valueOf(deck),0, 4);
    System.out.println(deck[L]);
    g.drawImage(image, 100, 100, this );
    L = L + 1;
    }
    }
    }

    what i want to do is put one random card (deck[L]) into each players hand. and output that image onto the screen.


    but i keep getting this error:

    H:\Comp390\March2>javac DeckOfCards.java
    DeckOfCards.java:141: incompatible types
    found : Card
    required: Hand
    hand[i][j] = deck[L];
    ^
    1 error


    i have attatched the whole of my code if it helps.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    i answered the question over on codeguru...did it not help at all? the reason it won't work is because you're telling java to make a hand equal to a card, which makes no sense. instead you need to make java add a card to the hand by giving Hand a setCard method.

  3. #3
    Join Date
    Mar 2004
    Posts
    2
    Yes your message did help but i posted to both sites on same day so i didn't get your one til after i posted both.

    I have decided to start again. I have attatched my new version.
    instead of creating the object card straight away i decided to make thwe structure surrounding an index number.

    public int [][]Hand;
    public int [] Deck;

    means that when i shuffle the deck i get 52 random numbers which when put into a hand, corresponds to a picture card ( 1.Gif, 2.Gif, 3.Gif etc).

    The program works fine i can shuffle the deck deal a number to a player. But, i'm not sure how i go about the graphics structure.

    i used

    // ---------- Paint Card ----------------
    public void paint ( Graphics g )
    {
    image = Toolkit.getDefaultToolkit
    ().getImage( "cards/" + (Hand[i][j]) + ".gif");
    g.drawImage(Card, 100, 100, this );
    }


    but the picture only comes on screen when i minimise the window and get it back again, or when i goto another open program and then back again.

    do i need an update() or something?
    I am also having trouble understanding how i can go about keeping the card on screen and at the same time have the other cards over the top but slightly to the right to give the effect of a fanned hand.
    Can you give me any hints on how to do this?
    also i always get runtime error messages in dos.
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    sorry, i didn't realise they'd both been posted at once. Anyway, i posted an answer to your new question on the other forum. Hope it helps....but GUI's really aren't my thing hehe. Too arty for me so haven't had enough practice with them

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center