This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about GUI JtextArea and printing the cards  RSS feed

 
Will Davis William
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its my first GUI assignment. I have made a card game which has sample output below. Now i have to print the card according to four players in a panel by JLabel. Meanwhile, i have to print the below format to a JtextArea beside the panel.

I have two class CardGame (organize the game logic) and CardGameTable (manage the GUI of game).
1) How can i print the cards according to the card game in GUI? Any sample can provide me for reference?
2)How can i print the below text on JtextArea?

Thanks a lot
<Player 0>
0 [ ] 1 [ ] 2 [ ] 3 [ ] 4 [ ] 5 [ ] 6 [ ] 7 [ ] 8 [ ] 9 [ ] 10 [ ] 11 [ ] 12 [ ]
<Player 1>
0 [ ] 1 [ ] 2 [ ] 3 [ ] 4 [ ] 5 [ ] 6 [ ] 7 [ ] 8 [ ] 9 [ ] 10 [ ] 11 [ ] 12 [ ]
<Player 2>
0 [ ] 1 [ ] 2 [ ] 3 [ ] 4 [ ] 5 [ ] 6 [ ] 7 [ ] 8 [ ] 9 [ ] 10 [ ] 11 [ ] 12 [ ]
<Player 3>
==> 0 [♦3] 1 [♣3] 2 [♦5] 3 [♣5] 4 [♥5] 5 [♠5] 6 [♥7] 7 [♠7] 8 [♠9] 9 [♥0] 10 [♦J] 11 [♠Q] 12 [♦A]
<Table>
[Empty]
Player 3's turn:
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What sort of public interface do you have on your game application? How many classes does it have? It should probably have a Card class, a Hand class, a Player class and a Game class, but that is a bare minimum. Can you get any sort of data structure containing the different hands from the application?
As for cards, have you read the Java® Language Specification (=JLS) about enumerated types? The JLS can be difficult to read, but they use cards as an example in that section and you can probably understand the example easily. You might be able to use something similar.
 
Will Davis William
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for didnt explain briefly.
My game has Card(managing the each card) ,Deck(managing and initialize a deck of card gonna play) ,CardGame(the card game logic),CardGameTable (GUI),Hand(Check what hand is eg Flush), Cardlist (store and managing the cards which each player has)

 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like a better set of classes
Does your game class have a method which allows you to inspect a player's cards? Can you return anything representing a hand? Can you sort your hands? Look at this sort method, and this tutorial about ordering objects.
If you can return something representing a hand, you can use it to get the output displayed. Does the Hand#toString method return anything useful?

Did I see you have a 0♥ in your output? What does that mean?

Additional in edit: If you have an output from toString, you can set the text in a text Component:
myTextField.setText(myHand.toString());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!