Results 1 to 14 of 14
  1. #1
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Does not recognize drawImage method...

    I'm writing an applet code that loads a deck of cards, shuffles them, and then displays the first ten in two rows of five. I've written the code, and it seems (generally) correct to me, but I'm getting an error message (ten, really; one for every card that's pulled) -- it does not recognize the 'symbol' of the drawImage method. I imported everything I need to have imported, I think, but something's still amiss.

    Here's the code:

    Java Code:
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.util.Random;
    
    
    public class AppletDemo1 extends Applet
    {
    	Image card1, card2, card3, card4, card5, card6, card7, card8, card9, card10, card11, card12, card13, card14, card15, card16, card17, card18, card19, card20, card21, card22, card23, card24, card25, card26, card27, card28, card29, card30, card31, card32, card33, card34, card35, card36, card37, card38, card39, card40, card41, card42, card43, card44, card45, card46, card47, card48, card49, card50, card51, card52;
    
    	public void init()
    	{
    		card1 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c1.gif" );
    		card2 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c2.gif" );
    		card3 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c3.gif" );
    		card4 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c4.gif" );
    		card5 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c5.gif" );
    		card6 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c6.gif" );
    		card7 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c7.gif" );
    		card8 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c8.gif" );
    		card9 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c9.gif" );
    		card10 = getImage( getDocumentBase(), "http://www.java-forums.org/images/c10.gif" );
    		card11 = getImage( getDocumentBase(), "http://www.java-forums.org/images/cj.gif" );
    		card12 = getImage( getDocumentBase(), "http://www.java-forums.org/images/ck.gif" );
    		card13 = getImage( getDocumentBase(), "http://www.java-forums.org/images/cq.gif" );
    		card14 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d1.gif" );
    		card15 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d2.gif" );
    		card16 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d3.gif" );
    		card17 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d4.gif" );
    		card18 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d5.gif" );
    		card19 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d6.gif" );
    		card20 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d7.gif" );
    		card21 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d8.gif" );
    		card22 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d9.gif" );
    		card23 = getImage( getDocumentBase(), "http://www.java-forums.org/images/d10.gif" );
    		card24 = getImage( getDocumentBase(), "http://www.java-forums.org/images/dj.gif" );
    		card25 = getImage( getDocumentBase(), "http://www.java-forums.org/images/dk.gif" );
    		card26 = getImage( getDocumentBase(), "http://www.java-forums.org/images/dq.gif" );
    		card27 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h1.gif" );
    		card28 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h2.gif" );
    		card29 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h3.gif" );
    		card30 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h4.gif" );
    		card31 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h5.gif" );
    		card32 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h6.gif" );
    		card33 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h7.gif" );
    		card34 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h8.gif" );
    		card35 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h9.gif" );
    		card36 = getImage( getDocumentBase(), "http://www.java-forums.org/images/h10.gif" );
    		card37 = getImage( getDocumentBase(), "http://www.java-forums.org/images/hj.gif" );
    		card38 = getImage( getDocumentBase(), "http://www.java-forums.org/images/hk.gif" );
    		card39 = getImage( getDocumentBase(), "http://www.java-forums.org/images/hq.gif" );
    		card40 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s1.gif" );
    		card41 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s2.gif" );
    		card42 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s3.gif" );
    		card43 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s4.gif" );
    		card44 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s5.gif" );
    		card45 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s6.gif" );
    		card46 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s7.gif" );
    		card47 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s8.gif" );
    		card48 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s9.gif" );
    		card49 = getImage( getDocumentBase(), "http://www.java-forums.org/images/s10.gif" );
    		card50 = getImage( getDocumentBase(), "http://www.java-forums.org/images/sj.gif" );
    		card51 = getImage( getDocumentBase(), "http://www.java-forums.org/images/sk.gif" );
    		card52 = getImage( getDocumentBase(), "http://www.java-forums.org/images/sq.gif" );
    	}
    
    	public void paint( Graphics g )
    	{
    
    		String[] pics = {"card1","card2","card3","card4","card5","card6","card7","card8","card9","card10","card11","card12","card13","card14","card15","card16","card17","card18","card19","card20","card21","card22","card23","card24","card25","card26","card27","card28","card29","card30","card31","card32","card33","card34","card35","card36","card37","card38","card39","card40","card41","card42","card43","card44","card45","card46","card47","card48","card49","card50","card51","card52"};
    
    		int i;
    
    		for( i = 1 ; i <= 10; i++ )
    		{
    			int b = 0;
    			Random a = new Random();
    			b = a.nextInt(52) + 1;
    
    			if ( i == 1 )
    			{
    				g.drawImage( pics[b], 10, 10, this );
    			}
    			else if ( i == 2 )
    			{
    				g.drawImage( pics[b], 110, 10, this );
    			}
    			else if ( i == 3 )
    			{
    				g.drawImage( pics[b], 210, 10, this );
    			}
    			else if ( i == 4 )
    			{
    				g.drawImage( pics[b], 310, 10, this );		
    			}
    			else if ( i == 5 )
    			{
    				g.drawImage( pics[b], 410, 10, this );
    			}
    			else if ( i == 6 )
    			{
    				g.drawImage( pics[b], 10, 150, this );
    			}
    			else if ( i == 7 )
    			{
    				g.drawImage( pics[b], 110, 150, this );
    			}
    			else if ( i == 8 )
    			{
    				g.drawImage( pics[b], 210, 150, this );
    			}
    			else if ( i == 9 )
    			{
    				g.drawImage( pics[b], 310, 150, this );
    			}
    			else if ( i == 10 )
    			{
    				g.drawImage( pics[b], 410, 150, this );
    			}		 
    		}
    	}
    }

    Thanks, all!

    EDIT: Oh, it cuts off at card 20 up top and card 16 lower down. For the record, I've done that part correctly.

  2. #2
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    I'm writing an applet code that loads a deck of cards, shuffles them, and then displays the first ten in two rows of five. I've written the code, and it seems (generally) correct to me, but I'm getting an error message (ten, really; one for every card that's pulled) -- it does not recognize the 'symbol' of the drawImage method. I imported everything I need to have imported, I think, but something's still amiss.

    Here's the code:

    Java Code:
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.util.Random;
    
    
    public class AppletDemo1 extends Applet
    {
    	Image card1, card2, card3, card4, card5, card6, card7, card8, card9, card10, card11, card12, card13, card14, card15, card16, card17, card18, card19, card20, card21, card22, card23, card24, card25, card26, card27, card28, card29, card30, card31, card32, card33, card34, card35, card36, card37, card38, card39, card40, card41, card42, card43, card44, card45, card46, card47, card48, card49, card50, card51, card52;
    
    	public void init()
    	{
    		card1 = getImage( getDocumentBase(), "images/c1.gif" );
    		card2 = getImage( getDocumentBase(), "images/c2.gif" );
    		card3 = getImage( getDocumentBase(), "images/c3.gif" );
    		card4 = getImage( getDocumentBase(), "images/c4.gif" );
    		card5 = getImage( getDocumentBase(), "images/c5.gif" );
    		card6 = getImage( getDocumentBase(), "images/c6.gif" );
    		card7 = getImage( getDocumentBase(), "images/c7.gif" );
    		card8 = getImage( getDocumentBase(), "images/c8.gif" );
    		card9 = getImage( getDocumentBase(), "images/c9.gif" );
    		card10 = getImage( getDocumentBase(), "images/c10.gif" );
    		card11 = getImage( getDocumentBase(), "images/cj.gif" );
    		card12 = getImage( getDocumentBase(), "images/ck.gif" );
    		card13 = getImage( getDocumentBase(), "images/cq.gif" );
    		card14 = getImage( getDocumentBase(), "images/d1.gif" );
    		card15 = getImage( getDocumentBase(), "images/d2.gif" );
    		card16 = getImage( getDocumentBase(), "images/d3.gif" );
    		card17 = getImage( getDocumentBase(), "images/d4.gif" );
    		card18 = getImage( getDocumentBase(), "images/d5.gif" );
    		card19 = getImage( getDocumentBase(), "images/d6.gif" );
    		card20 = getImage( getDocumentBase(), "images/d7.gif" );
    		card21 = getImage( getDocumentBase(), "images/d8.gif" );
    		card22 = getImage( getDocumentBase(), "images/d9.gif" );
    		card23 = getImage( getDocumentBase(), "images/d10.gif" );
    		card24 = getImage( getDocumentBase(), "images/dj.gif" );
    		card25 = getImage( getDocumentBase(), "images/dk.gif" );
    		card26 = getImage( getDocumentBase(), "images/dq.gif" );
    		card27 = getImage( getDocumentBase(), "images/h1.gif" );
    		card28 = getImage( getDocumentBase(), "images/h2.gif" );
    		card29 = getImage( getDocumentBase(), "images/h3.gif" );
    		card30 = getImage( getDocumentBase(), "images/h4.gif" );
    		card31 = getImage( getDocumentBase(), "images/h5.gif" );
    		card32 = getImage( getDocumentBase(), "images/h6.gif" );
    		card33 = getImage( getDocumentBase(), "images/h7.gif" );
    		card34 = getImage( getDocumentBase(), "images/h8.gif" );
    		card35 = getImage( getDocumentBase(), "images/h9.gif" );
    		card36 = getImage( getDocumentBase(), "images/h10.gif" );
    		card37 = getImage( getDocumentBase(), "images/hj.gif" );
    		card38 = getImage( getDocumentBase(), "images/hk.gif" );
    		card39 = getImage( getDocumentBase(), "images/hq.gif" );
    		card40 = getImage( getDocumentBase(), "images/s1.gif" );
    		card41 = getImage( getDocumentBase(), "images/s2.gif" );
    		card42 = getImage( getDocumentBase(), "images/s3.gif" );
    		card43 = getImage( getDocumentBase(), "images/s4.gif" );
    		card44 = getImage( getDocumentBase(), "images/s5.gif" );
    		card45 = getImage( getDocumentBase(), "images/s6.gif" );
    		card46 = getImage( getDocumentBase(), "images/s7.gif" );
    		card47 = getImage( getDocumentBase(), "images/s8.gif" );
    		card48 = getImage( getDocumentBase(), "images/s9.gif" );
    		card49 = getImage( getDocumentBase(), "images/s10.gif" );
    		card50 = getImage( getDocumentBase(), "images/sj.gif" );
    		card51 = getImage( getDocumentBase(), "images/sk.gif" );
    		card52 = getImage( getDocumentBase(), "images/sq.gif" );
    	}
    
    	public void paint( Graphics g )
    	{
    
    		String[] pics = {"card1","card2","card3","card4","card5","card6","card7","card8","card9","card10","card11","card12","card13","card14","card15","card16","card17","card18","card19","card20","card21","card22","card23","card24","card25","card26","card27","card28","card29","card30","card31","card32","card33","card34","card35","card36","card37","card38","card39","card40","card41","card42","card43","card44","card45","card46","card47","card48","card49","card50","card51","card52"};
    
    		int i;
    
    		for( i = 1 ; i <= 10; i++ )
    		{
    			int b = 0;
    			Random a = new Random();
    			b = a.nextInt(52) + 1;
    
    			if ( i == 1 )
    			{
    				g.drawImage( pics[b], 10, 10, this );
    			}
    			else if ( i == 2 )
    			{
    				g.drawImage( pics[b], 110, 10, this );
    			}
    			else if ( i == 3 )
    			{
    				g.drawImage( pics[b], 210, 10, this );
    			}
    			else if ( i == 4 )
    			{
    				g.drawImage( pics[b], 310, 10, this );		
    			}
    			else if ( i == 5 )
    			{
    				g.drawImage( pics[b], 410, 10, this );
    			}
    			else if ( i == 6 )
    			{
    				g.drawImage( pics[b], 10, 150, this );
    			}
    			else if ( i == 7 )
    			{
    				g.drawImage( pics[b], 110, 150, this );
    			}
    			else if ( i == 8 )
    			{
    				g.drawImage( pics[b], 210, 150, this );
    			}
    			else if ( i == 9 )
    			{
    				g.drawImage( pics[b], 310, 150, this );
    			}
    			else if ( i == 10 )
    			{
    				g.drawImage( pics[b], 410, 150, this );
    			}		 
    		}
    	}
    }

    Thanks, all!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Does not recognize drawImage method...

    You need to post the entire error message. If you did, we could point out to you why Java isn't recognizing the method -- hint, are you passing an image into the method's first parameter? or a String? Which should be passed in?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Does not recognize drawImage method...

    Does the Graphics class have a drawImage method with (String, int, int, Applet) as its parameters?

  5. #5
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    It says this (x10, of course, and dependant on which i value it is):

    AppletDemo1.java:82: cannot find symbol
    symbol : method drawImage<java.lang.String,int,int,AppletDemo1>
    location : class java.awt.graphics

    g.drawImage< pics[b], 10, 10, this >;
    It's highlighted right below the period between "g" and "draw".

    As for the second part of your comment, I am passing in "cardx" where x is a number between 1 and 52 that has already been assigned an image.

  6. #6
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    Quote Originally Posted by Junky View Post
    Does the Graphics class have a drawImage method with (String, int, int, Applet) as its parameters?
    I would think that if, say, 'card 3' is already assigned an Image to work with, finding it in a String and then using that to load the image shouldn't be a problem.

    For instance, if instead of pics[b] I wrote card3, it would work, wouldn't it?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Does not recognize drawImage method...

    What is pics an array of? Image or String? Remember that the compiler is not very forgiving. It has no idea that if you are using a String that you mean instead the variable with the same name.

  8. #8
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    It's a string of images, effectively.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Does not recognize drawImage method...

    Quote Originally Posted by Koba View Post
    It's a string of images, effectively.
    There is no such animal, "effectively". It's either an array of String or an array of Images. And how do you declare it? -- hint String[] pics. It can't be any clearer.

  10. #10
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    Ok, so it's an array of string. Each of the components of the array are images, though, aren't they?

    I now see the second part of your earlier post. Would it make sense to just scrap the array/string entirely and find some other way to call the variable "cardx" depending on the integer that I get from the random number generator?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Does not recognize drawImage method...

    If this were my code, I would create create an array of String and and array of Image and use one to create the other. For instance,...

    Java Code:
          String[] imageNames = { "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8",
                "c9", "c10", "cj", "ck", "cq", "d1", .... this goes on of course };
    
          Image[] images = new Image[imageNames.length];
    
          for (int i = 0; i < imageNames.length; i++) {
             String imagePath = "http://www.java-forums.org/images/" + imageNames
                   + ".gif";
             images[i] = getImage(getDocumentBase(), imagePath);
          }
    Then I'd have all my images nicely in an array.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Does not recognize drawImage method...

    Quote Originally Posted by Koba View Post
    Ok, so it's an array of string. Each of the components of the array are images, though, aren't they?
    No!!! they're Strings of course. Variable names and a String that looks like it have no equivalence whatsoever!

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Does not recognize drawImage method...

    Quote Originally Posted by Koba View Post
    Ok, so it's an array of string. Each of the components of the array are images, though, aren't they?
    Of course not!

    If you declare an array with a certain type then the only thing you can store in it are things of that type. Just because you think that a certain String represents a certain Image, how the heck is the compiler supposed to read your mind and know that you really mean an Image?

  14. #14
    Koba is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Does not recognize drawImage method...

    Such a simple fix, thank you both.

Similar Threads

  1. NullPointerException on Graphics.drawImage
    By Jaeela in forum New To Java
    Replies: 5
    Last Post: 10-05-2011, 02:36 AM
  2. DrawImage with transparency ?
    By mrhid6 in forum AWT / Swing
    Replies: 2
    Last Post: 10-01-2011, 11:58 PM
  3. Recognize shapes from pictures
    By acole5 in forum New To Java
    Replies: 9
    Last Post: 06-20-2011, 08:14 PM
  4. drawImage im 13 plz help
    By pseudohawtcakes in forum New To Java
    Replies: 3
    Last Post: 05-17-2011, 08:07 PM
  5. Recognize HDD, CD/ROM, DVD/ROM drives
    By xmikul28 in forum Advanced Java
    Replies: 3
    Last Post: 08-25-2009, 01:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •