Results 1 to 1 of 1
  1. #1
    aza101 is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default output not what expected!

    Hi. i have a simple Playing Card applet that puts 2 PlayingCard Objects from an arraylist, into a Player Object, the applet displays images at the PlayingCard Object pos x and y. The graphical output is not right i have tried double buffering which creates worse problems. please help.

    You will need 52 images to diplay the cards in order to load the applet. i am using getDocumentBase() to add file extension.

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.ArrayList;
    
    
    public class pokGraph1point2 extends java.applet.Applet  implements  MouseListener, MouseMotionListener {
    
    int mx,my;
    int iPlayersCount=10;
    Image imgPokerTable;
    
    
    ArrayList arraylst_Deck = new ArrayList();   ArrayList arraylst_CommunityCards = new ArrayList();	
    ArrayList arraylst_Players = new ArrayList(10);
    
    	public void init() 
    	{
    		
        		
        		for(int i=1;i<6;i++)
    			{
        			int z=10;
        			if(i==1||i==5)
        			{
        				z=60;
        			}
        			arraylst_Players.add(new Player(i*130,z));
    			}
    			for(int i=1;i<6;i++)
    			{
    				int z=320;
        			if(i==1||i==5)
        			{
        				z=270;
        			}
    				
        			arraylst_Players.add(new Player(i*130,z));
    			}
    			addMouseListener( this ); addMouseMotionListener( this );					
        		loadDeck();	
        		imgPokerTable=getImage( getDocumentBase(), "pokerTable.jpg" );
    
    			repaint();				
    	}		
      		
      	public void loadDeck()
      	{  	
    			int tempX=160;
    			for(int i=1;i<14;i++)
    			{
    					String tempStr=new String( Integer.toString(i) );
    					arraylst_Deck.add(new PlayingCard(tempX,520,"C",i,getImage( getDocumentBase(), tempStr + "c.png")));
    					tempX=tempX+19;	
    			}	
    			for(int i=1;i<14;i++)
    			{
    					String tempStr=new String( Integer.toString(i) );
    					arraylst_Deck.add(new PlayingCard(tempX,520,"S",i,getImage( getDocumentBase(), tempStr + "s.png")));	
    					tempX=tempX+19;											
    			}
    			tempX=160;			
      			for(int i=1;i<14;i++)
    			{
    					String tempStr=new String( Integer.toString(i) );
    					arraylst_Deck.add(new PlayingCard(tempX,560,"H",i,getImage( getDocumentBase(), tempStr + "h.png")));	
    					tempX=tempX+19;						
    			}		
             	for(int i=1;i<14;i++)
    			{
    				String tempStr=new String( Integer.toString(i) );
    					arraylst_Deck.add(new PlayingCard(tempX,560,"D",i,getImage( getDocumentBase(), tempStr + "d.png")));	
    					tempX=tempX+19;
    			}	
        }
    	public void clearAllCards()
    	{	        		
    	}
    
    	public void mouseEntered( MouseEvent e ) {} public void mouseExited( MouseEvent e ) {}public void mouseClicked( MouseEvent e ) {}public void mouseReleased( MouseEvent e ) {}public void mouseDragged( MouseEvent e ) {}
    	
    	
    	public void mousePressed( MouseEvent e )
    	{				
    			  for(int i=0; i<arraylst_Deck.size();i++)  //switch card from deck to playerhand arraylist
    			  {	 
                		 PlayingCard playingCard = (PlayingCard)arraylst_Deck.get(i); 	
                		 if((mx > playingCard.getposX() & mx < (playingCard.getposX()+20)) && (my > (playingCard.getposY()) & my < (playingCard.getposY()+35)))
                		 {  	
                		 	    for(int k=0; k<iPlayersCount; k++)
                		 	    {
                		 	    	Player oPlayer = (Player)arraylst_Players.get(k);
                		 	    	if (oPlayer.needsCard1()==true)
                		 	    	{
                		 	    			oPlayer.addCard(playingCard);
                		 	    			arraylst_Deck.remove(i);
                		 	    			 i=arraylst_Players.size(); break;  //break loop
                		 	    	}	
                		 	    	else if (oPlayer.needsCard2()==true)
                		 	    	{
                		 	    			oPlayer.addCard(playingCard);
                		 	    			arraylst_Deck.remove(i);
                		 	    			 i=arraylst_Players.size();break; 
                		 	    	}	
                		 	    }	   
                		 }	  	
    			  } 
     	
    			  for(int i=0; i<iPlayersCount;i++)  //switch card from deck to playerhand arraylist
    			  {
    			  	Player oPlayer = (Player)arraylst_Players.get(i);
    			  	
    			  	
    			  	PlayingCard oCard1 = oPlayer.getPlayingCard1();	
    			  	PlayingCard oCard2 = oPlayer.getPlayingCard2();	
    			  	if((mx > oCard1.getposX() & mx < (oCard1.getposX()+20)) && (my > (oCard1.getposY()) & my < (oCard1.getposY()+35)))
                 	 {  
                 	 arraylst_Deck.add(oCard1);	
                 	 	oPlayer.removeCard1();
                 	 	i=12;break;
               		 }
               		 else if((mx > oCard2.getposX() & mx < (oCard2.getposX()+20)) && (my > (oCard2.getposY()) & my < (oCard2.getposY()+35)))
                 	 {  
                 	 	arraylst_Deck.add(oCard2);	
                 	 	oPlayer.removeCard2();
                 	 	i=12;break;
               		 }
    			  		 	
    			  }	
    			  	
    			  	          	  	
    		repaint();
    	}
    		
    	public void mouseMoved( MouseEvent e )
    	{
     	 	  mx = e.getX(); my = e.getY();     
        	  repaint();
        	  e.consume(); 	
    	}
    
    	public void paint(Graphics g) 
    	{		
    		this.setSize( 900, 600 );
          	String s = new String();	
          
          	for(int i=0; i<iPlayersCount;i++)
      		{	
          		Player oPlayer = (Player)arraylst_Players.get(i);
          		if(oPlayer.needsCard1()==false)
          		{
          			PlayingCard oCard1 = oPlayer.getPlayingCard1();  
          					
          			s = s + oCard1.getCardSuit() + "  " + Integer.toString(oCard1.getCardFace());
          			g.drawString(s,10,10);	
          				
          			g.drawImage( oCard1.getLargeImage(), oPlayer.getposX(), oPlayer.getposY(),  this );		
          		}	
          		
          		if(oPlayer.needsCard2()==false)
          		{
          			PlayingCard oCard2 = oPlayer.getPlayingCard2();
          					
          			s = s + oCard2.getCardSuit() + "  " + Integer.toString(oCard2.getCardFace() )+ "           " ;
          			g.drawString(s,10,10);	
          				
          			g.drawImage( oCard2.getLargeImage(), oPlayer.getposX()+20, oPlayer.getposY(),  this );	
          		}		
      		}
            for(int q=0; q<arraylst_Deck.size();q++)
      		{	
            		PlayingCard pCard = (PlayingCard)arraylst_Deck.get(q);  				
            		g.drawImage( pCard.getLargeImage(), pCard.getposX(), pCard.getposY(),  this );	  	
      		} 											     		    			 		
    	}
    
    
      public class Player
      {		
    		int posX,posY;
    		ArrayList playersHand = new ArrayList(3);
    		boolean bNeedsCard1=true, bNeedsCard2=true;
    				
    		public Player(int a, int b) 
      		{
      				posX = a;  posY = b;  						 			
      		}	
     
      		public void addCard(PlayingCard x) 
      		{
      			if(playersHand.size()==0)
      			{
      			x.setposX(posX);     x.setposY(posY);		
      			playersHand.add(x);
      			bNeedsCard1=false;	
      			}
      			else if(playersHand.size()>0&&playersHand.size()<2)
      			{
      			x.setposX(posX);     x.setposY(posY);		
      			playersHand.add(x);
      			bNeedsCard2=false;
      			}	
      		}
     	public void removeCard1() 
      		{		
      			playersHand.remove(0);
      			bNeedsCard1=true;
      		}
      		public void removeCard2() 
      		{		
      			playersHand.remove(1);
      			bNeedsCard2=true;
      		}
      		public boolean needsCard1() {return bNeedsCard1;}   public boolean needsCard2() {return bNeedsCard2;} 	
      					
      		public int getposX() {return posX;}     public int getposY() {return posY;}
      				
      		public PlayingCard getPlayingCard1() 
      		{
      			PlayingCard pCard = (PlayingCard) playersHand.get(0);	return pCard;
      		}	
      		public PlayingCard getPlayingCard2() 
      		{
      			PlayingCard pCard = (PlayingCard) playersHand.get(1);	return pCard;
      		}		
      }
    
      public class PlayingCard
      {		
    		int posX,posY,iFace;
    		String sSuit = new String();
    		Image large_cardImage ;
    				
    		public PlayingCard(int a, int b,String d,int c,  Image e) 
      		{
      				posX = a;  posY = b;  					 			
      				iFace=c;  sSuit=d;	
      				large_cardImage = e;
      		}	
      	
      		public void setposX(int x) {posX=x;}	    // mutators
      		public void setposY(int y) {posY=y;}
      				
      			
      	 	public Image getLargeImage() {return large_cardImage;}	//accessors	  
    				
      		public int getposX() {return posX;}
      		
      		public int getposY() {return posY;}
      				
      		public int getCardFace() {return iFace;}
      		
      		public String getCardSuit() {return sSuit;}		
    	}
    
    }
    Last edited by Fubarable; 07-10-2009 at 07:02 AM. Reason: code tags added for readability

Similar Threads

  1. .class expected
    By dre in forum New To Java
    Replies: 6
    Last Post: 06-27-2009, 06:01 PM
  2. The values are NOT as expected...
    By Abder-Rahman in forum New To Java
    Replies: 4
    Last Post: 05-09-2009, 12:01 AM
  3. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  4. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 04:49 PM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 02:21 AM

Posting Permissions

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