Results 1 to 8 of 8
  1. #1
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default getText() and set

    hi guys, how i can do something like that:

    Java Code:
    String texto = contentor1 .getText(); 
    contentor1.setText(myDeckOfCards.giveCard());

    give an error:

    The method setText(String) in the type JTextComponent is not applicable for the arguments (Card)

    any idea?

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    What does method giveCards() return? setText() method require a String.

  3. #3
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by mine0926 View Post
    What does method giveCards() return? setText() method require a String.
    that's the problem, isn't a string, The method giveCards() return a card

    Java Code:
    	deck myDeckOfCards = new deck(); 
    		myDeckOfCards.shuffle(); 
    
    		System.out.println("You have this card : " + myDeckOfCards.giveCard());
    How i can do the transposition to a setText(); ?

    I wan't to show a random card in a JTextField...

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Can you show your giveCard() method? I cannot suggest anything since I do not see giveCard() method.

  5. #5
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default

    here is it


    Java Code:
    	public Card giveCard(){
    		if ( currentCard < deckOfCards.length )
    			return deckOfCards [currentCard++]; 
    		else        
    			System.out.println("No more Cards.");
    		return null;
    	}

  6. #6
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Create a method in your Card that convert gives its name ot at least convert it
    to a string

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default

    Add an appropriate toString method to your Card class. Then you can do:
    Java Code:
    contentor1.setText(myDeckOfCards.giveCard()[B].toString()[/B]);

  8. #8
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

Similar Threads

  1. Help with getText()
    By geekchick in forum New To Java
    Replies: 17
    Last Post: 08-06-2010, 05:36 PM
  2. getText(); problem
    By The_Sponzy_Paradox in forum Java Applets
    Replies: 5
    Last Post: 04-22-2010, 03:07 AM
  3. What format is a getText()?
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 01:43 AM
  4. gettext problems
    By gisler in forum AWT / Swing
    Replies: 3
    Last Post: 12-01-2009, 07:35 PM
  5. how to getText() properly?
    By javamula in forum New To Java
    Replies: 12
    Last Post: 09-16-2009, 05:45 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
  •