Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 309,237 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,741 people online right now. Registration is fast and FREE... Join Now!




Image from file on simple java application

 

Image from file on simple java application, How to Put images for the following code...

dmmh_22

25 Aug, 2009 - 09:10 AM
Post #1

New D.I.C Head
*

Joined: 13 Aug, 2009
Posts: 9


My Contributions
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...

CODE
import javax.swing.JOptionPane;

public class LuckyNine {
    

    public static void main(String[] args) {
    int rc = 0;  // The return code from the showConfirmDialog
do
      {  
      playGame();
         rc = JOptionPane.showConfirmDialog( null, "Play again?",
            "Question", JOptionPane.YES_NO_OPTION );
      } while ( rc == JOptionPane.YES_OPTION );
   }

private static void playGame ()
   {
  int pera = 0;  
  int rc = 0;  // The return code from the showConfirmDialog
    int deal = 2;     //dealing of cards
    int betplayer;
    int money = 1000;
    int sum = 0;
    String dealt; //string of dealing card
    String bet;

    //String[] lead = new String[dealer];
    String 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);
  
    
    int[] valueOfCard = new int[DECK];  
    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;

    System.out.println( "\n" + "Cards of " + name+ "\n" );
    for ( int y = 0; y < deal; y++, counter++){          
            System.out.print(shuffle[counter]);  
            System.out.println();
         sum+= valueOfCard[counter];
        }

    System.out.println( "\nSum of " + name + " is : " );

    if (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++){
        System.out.print(shuffle[counter]);
        System.out.println();
        sum += valueOfCard[counter];
    }
        
    System.out.println( "\n" + "Sum of dealer is : ");

    if (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( "Dealer's money is : " + pera );      
            }
        else
            {
            System.out.println( name + " WINS!! " );
            pera = money + betplayer;
            System.out.println( "Your money is : " + pera );
            }
        }

}


}




User is offlineProfile CardPM
+Quote Post



Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 09:08AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month