Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree1Likes

Thread: how to generate 10 random card Images in applet graphics

  1. #1
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default how to generate 10 random card Images in applet graphics

    Please help me How can I generate random cards, cards is have type Image img;
    So I want to draw random 10 random cards from 104, I have tied but not solving, please help me.......
    My Applet code is:-
    ShowCard.java
    Java Code:
    package com.progresso;
    
    import java.applet.AudioClip;
    import java.awt.Button;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Random;
    
    
    import javax.swing.JApplet;
    
    public class ShowCard extends JApplet implements MouseListener, 
    MouseMotionListener {
    
    	
    	private static final long serialVersionUID = 1L;
    	Image image,image1,img,img1,Casino_table_img;
    	MediaTracker tr;
        int x=5;
        int y=5;
      	private static final int IMAGE_WIDTH = 73;
        private static final int IMAGE_HEIGHT = 97;
        private int _initX     = 0;   // x cord - set from drag
        private int _initY     = 150;   // y cord - set from drag
        
        /** Position in image of mouse press to make dragging look better. */
        private int _dragFromX = 0;  // Displacement inside image of mouse press.
        private int _dragFromY = 0;
        
        private static ShowCard[] _deck = new ShowCard[104];
        public Image[] card = new Image[104];
        public Boolean[] nums = new Boolean[52];
        private ShowCard _currentCard = null;  
        Button play,stop;
        AudioClip audioClip;
        String suits = "shdcshdc";
        String faces = "a23456789tjqk";
        int cardPosition = 0;
        private Random ran;
      
        private int[] x1 = {200,220,240,260,280,300,320,340,360,380};
        private int[] y1 = {320,320,320,320,320,320,320,320,320,320};
        private int[] x2 = {200,220,240,260,280,300,320,340,360,380};
        private int[] y2 = {110,110,110,110,110,110,110,110,110,110};
        private int[] x3 = {305};
        private int[] y3 = {210};
        BufferedImage[] images;
        
        
    
    
        
            public ShowCard()
            {
            	Demo1(image,x,y);
            }
            public ShowCard(Image image, int x, int y) {
        	
            	
            this.x = x;
            this.y = y;
           
    		}
    	   public void Demo1(Image image, int x, int y)  //here x and y is 0-51;
           {
           
         	
            this.x = x;
            this.y = y;
           }
    	
    	  public void init()
    	   {
    		  
    		  setSize(500, 500);
    		  audioClip = getAudioClip(getCodeBase(), "audio/TestSnd.wav");
    		  img1 = getImage(getCodeBase(),"cards/b.gif");
    		  Casino_table_img = getImage(getCodeBase(),"cards/casino_table2.gif");
    		 
    	      ran = new Random();
            try {        
            	
            	System.out.println("1");
            for (int suit=0; suit<suits.length(); suit++) 
            {
                for (int face=0; face<faces.length(); face++) 
                {
                	
                	
                	img = getImage(getCodeBase(),"cards/"+ faces.charAt(face)
                             + suits.charAt(suit) + ".gif");
                	//card=getImage(getCodeBase(),"cards/"+ faces.charAt(face)
                           // + suits.charAt(suit) + ".gif");
                	
                    _deck[cardPosition++] = new ShowCard(image, _initX++, _initY++);
                   
                }
               
            }
           }catch (Exception ex) {
            	ex.printStackTrace(System.out); 
                // handle exception...
           }
           
           
            this.addMouseListener(this); 
            this.addMouseMotionListener(this);
            
    	   }
    	  public void start()
    	  {
    		  System.out.println("Start");
    		  
    	  }
    	  public void paint(Graphics g) 
    	  	{
    		  g.setColor(Color.BLUE);
    	    	System.out.println("paint");
    	        super.paintComponents(g);   // Required
    	        int crd=0;
    	        g.drawImage(Casino_table_img, 20, 20, this);
    	        try{
    	         for (crd=0; crd<_deck.length; crd++) {
    	        	 ShowCard c = _deck[crd];
    	             g.drawImage(img, c.x,c.y, this);
    	             g.drawImage(img1, c.x,c.y, this);
    	             
    	            //g.drawImage( card.remove(ran.nextInt(card.size())), c.x,c.y,  this );
    	        } 
    	        
    	        }catch (Exception e) {
    	          	System.err.println("Caught IOException: " + e.getMessage());
    			
    	        }
    	       
    	        // FOR TEN CARDS
    	        try{
    	        
    	            for(int j =0; j <10; j++)
    	            {
    	            	//System.out.println("First");
    	            	//g.drawImage( card.remove(ran.nextInt(img.size())), x1[j],y1[j], this );
    	                //g.drawImage( card.remove(ran.nextInt(card.size())), x2[j],y2[j], this );
    	                g.drawImage(img1,x2[j],y2[j], this);
    	                g.drawImage(img,x1[j],y1[j], this);
    	               
    	                
    	             
    	            }
    	            //g.drawImage( card.remove(ran.nextInt(card.size())), x3[0],y3[0], this );
    	            
    	       
    	           }catch (Exception e) {
    	           	e.printStackTrace(System.out);
    	           	System.err.println("Caught IOException: " + e.getMessage());
    	   		
    	           }
    	      
    	          
    	    }//end paintComponent
    	    
    		public void mousePressed(MouseEvent e) {
       int x = e.getX();   // Save the x cord of the click
            int y = e.getY();   // Save the y cord of the click
           
            
          
            _currentCard = null;
            for (int crd=_deck.length-1; crd>=0; crd--) {
            	ShowCard testCard = _deck[crd];
                if (x >= testCard.x && x <= (testCard.x + IMAGE_WIDTH)
                        && y >= testCard.y && y <= (testCard.y + IMAGE_HEIGHT)) {
                    _dragFromX = x - testCard.x;  // how far from left
                    _dragFromY = y - testCard.y;  // how far from top
                    _currentCard = testCard;  // Remember what we're dragging.
                                  
                    break;   // Stop when we find the first match.
                }
            }
        }//end mousePressed
        
     
        /** Set x,y to mouse position and repaint. */
        public void mouseDragged(MouseEvent e) {
            if (_currentCard != null) {   // Non-null if pressed inside card image.
                _currentCard.x = e.getX() - _dragFromX;
                _currentCard.y = e.getY() - _dragFromY;
                
                
                //--- Don't move the image off the screen sides
                _currentCard.x = Math.max(_currentCard.x, 0);
                _currentCard.x = Math.min(_currentCard.x, getWidth()-IMAGE_WIDTH);
               
                
                //--- Don't move the image off top or bottom
                _currentCard.y = Math.max(_currentCard.y, 0);
                _currentCard.y = Math.min(_currentCard.y, getHeight()-IMAGE_HEIGHT);
                
                this.repaint();
            }
        }//end mouseDragged
    
        public void mouseExited(MouseEvent e) {
            _currentCard = null;
            System.out.println("7");
        }//end mouseExited
    
        public void mouseMoved   (MouseEvent e) {  } 
        public void mouseEntered (MouseEvent e) {  } 
        public void mouseClicked (MouseEvent e) {  }
        public void mouseReleased(MouseEvent e)
        { 
        	audioClip.play();
        }
    	
    	
    }

    please please help me I am trying many times but not solving ,,,,,,,please

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,000
    Rep Power
    10

    Default Re: how to generate 10 random card Images in applet graphics

    Just put your images in an array, then generate 10 random numbers and use them as indexes. Or put all your cards in a List, shuffle the list, and take the first 10 elements.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    I have tried to put all the images in an array but not getting out put, please give me the solution where and how array will be used for draw random images....

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    tried to put all the images in an array but not getting out put
    Can you show your problem with using an array?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    I have declared array list of card as static ArrayList<Image> card;
    and draw g.drawImage( card.remove(ran.nextInt(card.size())), c.x,c.y, this );
    but not generate random images
    I have also tried with bufferimage also for creation a variable and store all the cards images and then generate random images but not solving,


    Please you help me and give solution step by step that I will do,.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    I have tried to put all the images in an array but not getting out put,
    Post the code that you tried to use and post the error messages.

    card.remove(ran.nextInt(card.size()))
    Break this compound statement into single statements and print out the results of each.
    Last edited by Norm; 04-19-2012 at 06:43 PM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    Quote Originally Posted by Norm View Post
    Post the code that you tried to use and post the error messages.


    Break this compound statement into single statements and print out the results of each.


    System.out.println( card.remove(ran.nextInt(card.size())));
    This line prints all the 104 cards as

    sun.awt.image.ToolkitImage@1b34126
    sun.awt.image.ToolkitImage@17a4989
    sun.awt.image.ToolkitImage@17200b4
    sun.awt.image.ToolkitImage@11946c2
    sun.awt.image.ToolkitImage@1f2cea2
    sun.awt.image.ToolkitImage@1dc0e7a
    .
    .
    .
    .
    etc........

    And Also Error at the following line

    g.drawImage( card.remove(ran.nextInt(card.size())), x1[j],y1[j], this );

    This line generate error, please tell me where I am wrong.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    Break this compound statement into single statements and print out the results of each.
    card.remove(ran.nextInt(card.size()))

    Can you explain why the selected images did not work?

    This line generate error,
    what error?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    error at this line is:


    java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    Caught IOException: n must be positive

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    As I have recommended twice before:

    Break this compound statement into single statements and print out the results of each.
    card.remove(ran.nextInt(card.size()))
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    System.out.println( card.remove(ran.nextInt(card.size())));
    This prints below content:
    This is you actually want?


    sun.awt.image.ToolkitImage@11dba45
    sun.awt.image.ToolkitImage@b03be0
    sun.awt.image.ToolkitImage@2af081
    sun.awt.image.ToolkitImage@113a53d
    sun.awt.image.ToolkitImage@c5495e
    sun.awt.image.ToolkitImage@53fb57
    sun.awt.image.ToolkitImage@19a32e0
    sun.awt.image.ToolkitImage@8238f4
    sun.awt.image.ToolkitImage@16925b0
    sun.awt.image.ToolkitImage@297ffb
    sun.awt.image.ToolkitImage@18bbc5a
    sun.awt.image.ToolkitImage@facf0b
    sun.awt.image.ToolkitImage@2f0df1
    sun.awt.image.ToolkitImage@13c6a22
    sun.awt.image.ToolkitImage@15c07d8
    sun.awt.image.ToolkitImage@10721b0
    sun.awt.image.ToolkitImage@134b07e
    sun.awt.image.ToolkitImage@2f48d2
    sun.awt.image.ToolkitImage@13c6a22
    sun.awt.image.ToolkitImage@55d93d
    sun.awt.image.ToolkitImage@d56b37
    sun.awt.image.ToolkitImage@1947496
    sun.awt.image.ToolkitImage@19a32e0
    sun.awt.image.ToolkitImage@fb6354
    sun.awt.image.ToolkitImage@364641
    sun.awt.image.ToolkitImage@15f7107
    sun.awt.image.ToolkitImage@10ffb38
    sun.awt.image.ToolkitImage@36527f
    sun.awt.image.ToolkitImage@6210fb
    sun.awt.image.ToolkitImage@48edb5
    sun.awt.image.ToolkitImage@2af081
    sun.awt.image.ToolkitImage@15f7107
    sun.awt.image.ToolkitImage@6782a9

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    No.
    Break this compound statement into single statements and print out the results of each.
    There are three sub parts to that statement, print each one separately.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    System.out.println( card.remove(ran.nextInt(card.size())));
    System.out.println( x1[j]);
    System.out.println( y1[j]);
    Generates this error on console:




    java.lang.IndexOutOfBoundsException: Index: 1051853454, Size: 104
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.remove(ArrayList.java:387)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)Caught IOException: Index: 1051853454, Size: 104

    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    Caught IOException: -1822360366
    java.lang.ArrayIndexOutOfBoundsException: -1822360366
    at java.util.ArrayList.remove(ArrayList.java:390)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    First
    java.lang.IndexOutOfBoundsException: Index: 569702490, Size: 104
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.remove(ArrayList.java:387)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    Caught IOException: Index: 569702490, Size: 104

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    This is what I was talking about: card.remove(ran.nextInt(card.size())));
    The results of these methods:
    size()
    nextInt()
    remove()

    I have tried to put all the images in an array but not getting out put,
    You still have not explained this problem.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    I am sorry the following line print as bellow, sorry for the wrong post error message.

    System.out.println( card.remove(ran.nextInt(card.size())));
    System.out.println( x1[j]);
    System.out.println( y1[j]);
    Generates this error on console:




    sun.awt.image.ToolkitImage@11dba45
    200
    320
    sun.awt.image.ToolkitImage@b03be0
    220
    320
    sun.awt.image.ToolkitImage@113a53d
    240
    320
    sun.awt.image.ToolkitImage@53fb57
    260
    320
    sun.awt.image.ToolkitImage@19a32e0
    280
    320
    sun.awt.image.ToolkitImage@16925b0
    300
    320
    sun.awt.image.ToolkitImage@297ffb
    320
    320
    sun.awt.image.ToolkitImage@1f4cbee
    340
    320
    sun.awt.image.ToolkitImage@787d6a
    360
    320
    sun.awt.image.ToolkitImage@53fb57
    380
    320
    sun.awt.image.ToolkitImage@1766806
    200
    320
    sun.awt.image.ToolkitImage@a77106
    220
    320
    sun.awt.image.ToolkitImage@eac5a
    240
    320
    sun.awt.image.ToolkitImage@15575e0
    260
    320
    sun.awt.image.ToolkitImage@cbdb20
    280
    320
    sun.awt.image.ToolkitImage@19f3736
    300
    320
    sun.awt.image.ToolkitImage@1e1dadb
    320
    320
    sun.awt.image.ToolkitImage@1e1dadb
    340
    320
    sun.awt.image.ToolkitImage@995a79
    360
    320
    sun.awt.image.ToolkitImage@1f4cbee
    380
    320
    sun.awt.image.ToolkitImage@113beb5
    200
    320
    sun.awt.image.ToolkitImage@1d95da8
    220
    320
    sun.awt.image.ToolkitImage@193f6e2
    240
    320
    sun.awt.image.ToolkitImage@1358f03
    260
    320
    sun.awt.image.ToolkitImage@1402d5a
    280
    320
    sun.awt.image.ToolkitImage@19a32e0
    300
    320
    sun.awt.image.ToolkitImage@61736e
    320
    320
    sun.awt.image.ToolkitImage@1e13e07
    340
    320
    sun.awt.image.ToolkitImage@af72d8
    360
    320
    sun.awt.image.ToolkitImage@9cfec1
    380
    320

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    This is the part I was talking about: card.remove(ran.nextInt(card.size())));
    Break it up and print The results of these methods:
    size()
    nextInt()
    remove()

    I have tried to put all the images in an array but not getting out put,
    You still have not explained this problem.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    Please solve my this error message when I am dragging one card this error message is print on console and other cards remove from the applet


    java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    Caught IOException: n must be positive
    Caught IOException: n must be positive
    java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    Caught IOException: n must be positive
    java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
    java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at com.progresso.ShowCard.paint(ShowCard.java:168)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:734)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)Caught IOException: n must be positive

    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    : n must be positive
    On line 168, Make sure n is a positive number.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: how to generate 10 random card Images in applet graphics

    If you really want any help with this problem, you MUST post a small, simple program that compiles, executes and shows the problem.
    Posting 2 lines of code and a hundred lines of error message text is a big waste of time.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: how to generate 10 random card Images in applet graphics

    Ok, now this line generate n must be positive error.

    g.drawImage( card.remove(ran.nextInt(card.size())), x1[j],y1[j], this );

    so where I am wrong.......

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 11-25-2011, 05:56 AM
  2. [Q] Generate Random Letter
    By iriscience in forum New To Java
    Replies: 11
    Last Post: 01-31-2011, 01:10 AM
  3. Random integer generate
    By trbLeeciN in forum New To Java
    Replies: 6
    Last Post: 06-22-2010, 02:19 AM
  4. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  5. Trying to Generate Random number
    By PeterFeng in forum New To Java
    Replies: 10
    Last Post: 01-14-2009, 09:37 AM

Tags for this Thread

Posting Permissions

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