Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 51

Thread: resetting label text alongside gui

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default resetting label text alongside gui

    Hi guys,

    I am a little stuck, the aim it reset the gui and the correct label.

    I only have the gui to reset, how do rest the correct label?(footer)
    Last edited by newtolearningjava; April 26th, 2014 at 05:57 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: resetting label text alongside gui

    What do you mean by "reset"? What have you tried? Where are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    reset as in bring the gui back to its original state so the game can be played again. which i can using this code [code] public void reset() {


    i have added a correct label in the code but i am not able to reset the text for that
    Last edited by newtolearningjava; April 26th, 2014 at 05:57 PM.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: resetting label text alongside gui

    Why aren't you able to reset the text for that JLabel?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    i am not sure on how do to this, that is why i asked and created the thread
    Last edited by newtolearningjava; April 14th, 2014 at 08:27 AM.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: resetting label text alongside gui

    You've posted code that sets the text of a JLabel. What is preventing you from using that code on the JLabel you want to reset?

    --- Update ---

    This thread has been cross posted here:

    http://stackoverflow.com/questions/23060521/reset-the-text-for-that-jlabel

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    nlmk
    Last edited by newtolearningjava; April 26th, 2014 at 05:58 PM.

  8. #8
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: resetting label text alongside gui

    footer.add(new JLabel("Correct: "));
    ...
    footer.add(new JLabel(buttonClicked.getText()));
    You're adding these JLabels to the footer, but you have no reference variable for them, so there's no direct way to set their text to "". But I don't think that's what you really want, I think you want to get rid of them altogether (because new ones will be created during the next game). In that case you're looking for footer.removeAll() and footer.revalidate().

  9. #9
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    here is my code i dont think i should get rid of them
    QUESTION IS
    Last edited by newtolearningjava; April 26th, 2014 at 05:58 PM.

  10. #10
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    help

  11. #11
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    the current code prints out "correct: 1,2,3,4") "1234 are the button click values" once these the game is over i want the label to go blank

  12. #12
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default remove text from label

    the current
    Last edited by newtolearningjava; April 26th, 2014 at 05:59 PM.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: remove text from label

    You have this:
    gui.correctLabel.setText("");
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: resetting label text alongside gui

    Baffled. I don't understand why the line below won't work.

    label.setText( "" );

    If you can provide more info as to why it is more difficult than that, please do.

    Duplicate threads merged.

  15. #15
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    i am not sure why myself, is spent a whole day trying to work it out but i have got no where. please can someone help me my head is going to explode
    Last edited by newtolearningjava; April 26th, 2014 at 05:59 PM.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: resetting label text alongside gui

    If the statement is not executed, the label is not cleared. Is the if statement true?
    if (gui.buttonCounter > gui.ROWS * gui.COLUMNS) {
    Add a println() statement to show the values used in that if statement to see what it sees when it is executed.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    Quote Originally Posted by Norm View Post
    If the statement is not executed, the label is not cleared. Is the if statement true?
    [code]

    Add a println() statement to show the values used in that if statement to see what it sees when it is executed.
    knllkmklkl
    Last edited by newtolearningjava; April 26th, 2014 at 05:59 PM.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: resetting label text alongside gui

    Did you have a question or comment?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    whats wrong with my code? why doesnt the
    Last edited by newtolearningjava; April 26th, 2014 at 06:00 PM.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: resetting label text alongside gui

    why doesnt the correctLabel take the buttonclicked values away from it?
    Sorry, that last post does not make sense. Labels don't interact. It's the code that makes changes to labels.


    What do you expect to be in each label AFTER that code executes?
    Give the name of the label and its expected contents.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    How do
    Last edited by newtolearningjava; April 26th, 2014 at 06:00 PM.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: resetting label text alongside gui

    make the correctLabel to have all the text disappear
    Execute this code:
    correctLabel.setText(" ");

    Is the program executing that code? If not, why isn't it?
    What are the values of the variables used in the if statement that controls if that statement is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    i think what the
    Last edited by newtolearningjava; April 26th, 2014 at 06:00 PM.

  24. #24
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: resetting label text alongside gui

    Quote Originally Posted by newtolearningjava View Post
    i think what the problem is that i have a seperate correct label, the label where the buttonclicked are shown is on a newJLabel.
                        footer.add(new JLabel(buttonClicked.getText()));
    Ya, I pointed that out to you several posts ago.

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: resetting label text alongside gui

    New labels without reference variables are hard to access if you want to change their values.
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 3 123 LastLast

Similar Threads

  1. Re: Resetting Accumulator after first itterneration
    By morrism35 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2013, 07:22 PM
  2. Text output in GUI
    By andreas81 in forum Java Theory & Questions
    Replies: 4
    Last Post: June 26th, 2013, 09:36 AM
  3. Button Text into Label text
    By bluewhale in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 6th, 2011, 10:15 AM
  4. Can't set label text from a Jbutton
    By VBGuy in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 8th, 2010, 10:55 AM