Hi.! uhm i just partially finished my card game project "Lucky Nine" in simple java application..

The results of the game are just printed in System.out.println, and i cant manage to turn it into just JOptionPane..

uhm, anyways, i need you guys to help me how to load images from file in just a simple java application, i havnt learned about jframes etc and my code is just ready for a simple java application..

can you help guys? the images is just all i wanted...

hope you still help me how to put for this code...

heres my code...

import javax.swing.JOptionPane;

public class LuckyNine_2 {
    

    public static void main(String[] args) {
    

   
  int pera = 0;  //money equivalent from the bet
  int rc = 0;  // The return code from the showConfirmDialog
    int deal = 2;     //dealing of cards
    int betplayer; //players bet
    int money = 1000; //players pot money is = 1000
    int sum = 0; //sum of cards
    String dealt; //string of dealing card
    String bet; //players bet asking to enter the bet

    //String[] lead = new String[dealer];
    String name; //ask players name
    String[] suit = { "Clubs", "Diamonds", "Hearts", "Spades" };//card suits
    String[] displayCard = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };  //52 cards to display 
    int DECK = displayCard.length * suit.length; //array length of displaycard and suit


    name = JOptionPane.showInputDialog("Enter name of player: ");
    bet = JOptionPane.showInputDialog( "Enter bet of " + name + ": " );
    betplayer = Integer.parseInt(bet);
  
    String[] playerdeck = new String[26]; //array of player's deck of cards
    String[] dealerdeck = new String[26]; //array of dealer's deck of cards
    int[] valueOfCardplayer = new int[DECK];  //value of player's card
    int[] valueOfCarddealer = new int[DECK];  //value of dealer's card
    int[] valueOfCard = new int[DECK];  //value of all cards
    String[] shuffle = new String[DECK]; /*method of combining & shuffling suit and displaycard */

    for (int i = 0; i < displayCard.length; i++){ 
        for (int j = 0; j < suit.length; j++){
      
            //method of the printing the cards
            shuffle[suit.length * i + j] = displayCard[i] + " of " + suit[j]; 

            if (displayCard[i]=="Jack")                         
                valueOfCard[suit.length * i + j]=0;
            else if (displayCard[i]=="Queen")
                valueOfCard[suit.length * i + j]=0;
            else if (displayCard[i]=="King")
                valueOfCard[suit.length * i + j]=0;
            else if (displayCard[i]=="Ace")
                valueOfCard[suit.length * i + j]=1;
            else if (displayCard[i]=="10")
                valueOfCard[suit.length * i + j]=0;
            else valueOfCard[suit.length * i + j]=Integer.parseInt(displayCard[i]);  
        }
    }
    
    //swapping and shuffling of cards
    for (int i = 0; i < DECK; i++){
        int index1 = i + (int) (Math.random() * (DECK - i));

        /*
        if (i!=0)
            {
            for (int x = 0; x < 
            }
        */
        
        String temp = shuffle[index1];
        shuffle[index1] = shuffle[i];
        shuffle[i] = temp;

        int temp2 = valueOfCard[index1];
        valueOfCard[index1] = valueOfCard[i];
        valueOfCard[i] = temp2;

    }
    
    int counter = 0;
    int count = 0;
    int winner = -1;
    int hand = 0; // basis deck of cards for hitting or stay
do
      {  
   
    System.out.println( "\n" + "Cards of " + name+ "\n" );
    
    for ( int y = 0; y < deal; y++, counter++, hand++){           
        playerdeck[hand] = shuffle[counter];
        valueOfCardplayer[hand] = valueOfCard[counter];
        
        }
    
    for ( int y = 0; y < hand; y++){           
    
            System.out.print(playerdeck[y]);  
            System.out.println();
            sum+= valueOfCardplayer[y];
        }
    hand = hand - deal;
    System.out.println( "\nSum of " + name + " is : " );

    while (sum > 9)
    {
    sum = sum - 10;
    }
    System.out.print( sum );
    System.out.println();

    if (sum == 9)
        {
        count++;
        winner=1;
        }
    
    sum = 0;

    System.out.println( "\n" + "cards of dealer is : " );
    for ( int y = 0; y < deal; y++, counter++, hand++){           
        dealerdeck[hand] = shuffle[counter];
        valueOfCarddealer[hand] = valueOfCard[counter];
        }
    
    for ( int y = 0; y < hand; y++){           
    
            System.out.print(dealerdeck[y]);  
            System.out.println();
            sum+= valueOfCarddealer[y];
        }
        
    System.out.println( "\n" + "Sum of dealer is : ");

    while (sum > 9)
        {
        sum = sum - 10;
        }    
    System.out.print( sum );
    System.out.println();

    if (sum == 9)
        {
        count++;
        winner=0;
        }

    if (count==0){        
        System.out.println( "\nNo WINNER..." );        
    
            pera = betplayer;
            System.out.println("Your money is still " + pera);
            }
    else if (count>1)
        System.out.println( "\nDRAW!!!" );
    else
        {
        if (winner==0){
            System.out.println( "Dealer WINS!! " );
            pera = money - betplayer;
            System.out.println( "Your money is : " + pera );       
            }
        else
            {
            System.out.println( name + " WINS!! " );
            pera = money + betplayer;
            System.out.println( "Your money is : " + pera );
            }
        }

       rc = JOptionPane.showConfirmDialog( null, "Do you want another card?",
            "Question", JOptionPane.YES_NO_OPTION );
        if (deal==2)
            deal--;
      } while ( rc == JOptionPane.YES_OPTION && deal < 52 );
     
      
   
}


}

i really need it badly...tnx guys..

Hello.

Loading images is pretty simple. The way I normally do it is by using the Toolkit method createImage(String path);

Image img = Toolkit.getDefaultToolkit().createImage(/** Image Path as String */);

Check out the java tutorial on images for a full explanation, and other, more efficient methods.

http://java.sun.com/docs/books/tutorial/2d/images/index.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.