Hello!

I have constucted a code for the card game 21. The code uses inputDialogs to "talk" the the player. I thought my shool assigment was over by doing just that...I was wrong, our teacher dumped a new bomb on us. With these kind words;

Develop task 5 (Twenty-one card game) by creating a complete graphical user interface (Graphical User Interface, GUI).

The graphic design will play a crucial role in the grading system.

Good luck.

Could anyone start me of? How much/where do I have to change my code and perhaps any pointers on how. Any guidelines.. I´got .gif images of all of the cards in a deck, not quite sure on how to make it all come together.

I am open to suggestions

My code:

public enum Value {
    TWO("2"),   THREE("3"),  FOUR("4"), FIVE("5"), SIX("6"), 
    SEVEN("7"),   EIGHT("8"), NINE("9"),  TEN("10"),
    JACK("J"), QUEEN("Q"),  KING("K"), ACE("A");
    public final int val = ordinal() + 2;
    public final String symbol;
    Value(String sym) {symbol = sym;}   
  }
public enum Suit {
   CLUBS('\u2663'),  DIAMONDS('\u2666'),
   HEARTS('\u2665'), SPADES('\u2660');
   public final char symbol;
   Suit(char c) {symbol=c;}   
 }
public class Deck {
   private Value v;
   private Suit s;

   public Deck(Value value, Suit suit) {
     s = suit;
     v = value;
   }

   public Suit suit() {  
     return s;
   }

   public Value values() { 
     return v;
   }

   public String toString() {
     return v.toString() + " " + s.toString();
   }

   public String toSymbol() {
     return v.symbol + s.symbol;
   }
 }
import java.util.*;

 public class DeckOfCards {
   private List<Deck> deckofcards = new LinkedList<Deck>();
   public void addTop(Deck d) {
     deckofcards.add(0, d);
   }

   public  Deck topAway() {
     Deck d = deckofcards.get(0);
     deckofcards.remove(0);
     return d;
   }

   public int noCards() {
     return deckofcards.size();
   }

   public void throwCards() {
     deckofcards.clear();
   }

   public Deck lookAt(int no) {
     return deckofcards.get(no);
   }

   public Deck remove(int no) {
     Deck d = deckofcards.get(no);
     deckofcards.remove(no);
     return d;
   }

   public int search(Suit s, Value v) {
     int i = 0;
     for (Deck d : deckofcards)
       if (d.values()==v && d.suit()==s)
         return i;
       else
         i++;
     return -1;
   }

   public void newDeck() {
     deckofcards.clear();
     for (Suit s : Suit.values())
       for (Value v : Value.values())
         deckofcards.add(new Deck(v, s));
   }
 
   public void mix() {
     Collections.shuffle(deckofcards);
   }
 }

[

import static javax.swing.JOptionPane.*;

 public class TwentyOne {
   public static void main(String[] arg) {
     DeckOfCards deck = new DeckOfCards();
     People you  = new People(deck);
     Computer I = new Computer(deck, you);
     while (true) {
       deck.newDeck();
       deck.mix();
       you.play();
       String s = "";
       if (you.points() > 21)
         s = "You lost!";
       else if (you.points() == 21)
         s = "You won!";
       else { 
         I.play();
         if (I.points() <= 21 && I.points() >= you.points())
           s = "You lost!";
         else
           s = "You won!";
       }
       int answere = showConfirmDialog(null, s + "\nNew game? ");
       if (answere != 0)
         break;
     }
   }
 }

I also have three other classes; Player, People and Computer. Were People and Computer is sub-classes to Player. I don´t think they are relevat to my question, if they are please advice me and I will add them to the thread aswell.

Well, since you didn't mention anything at all about your knowledge of Swing, this is the only starting point that we can give: http://java.sun.com/docs/books/tutorial/uiswing/index.html

I would recommend using JLabels to display your card graphics. You can easily lay out those JLabel components on a JPanel. Another label or text component can be used for your text outputs.

Well, since you didn't mention anything at all about your knowledge of Swing

I would say that I am mediocre, at using Swing.

I would recommend using JLabels to display your card graphics. You can easily lay out those JLabel components on a JPanel. Another label or text component can be used for your text outputs

How would you go about doing this? I can´t really get anywhere, my thoughts are totally blank.

Thank you!

class Hello{
public static void main(String args[])
{
System.out.println("Hello world")
}
}
this is the solution for your problem...

commented: Insulting and unhelpful post -1

You can display a graphic in a JLabel using the setImageIcon method - v easy and works v well.
Research layout managers to see how they allow you to lay out the labels in a window. a grid layout may be good for you.

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.