Results 1 to 7 of 7

Thread: Change text

  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Exclamation Change text

    I am writing a table tennis score program and every time two points (or the desired amount) have been played I want an arrow to face the opposite way that it faceing... This is the code so far. Please help!

    Java Code:
    private void Score()
          {
             String redd = scoreblue.getText();
             String bluee = scorered.getText();
             int red = Integer.parseInt(redd);
             int blue = Integer.parseInt(bluee);
            int rb = red+blue;
            int rbdiv = rb/2;
            if((rb) == (rbdiv == Integer))
             {
             pyl.setText("-->");
             }
          }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Change text

    a) Write a method that change/turns the arrow
    b) if(points % desiredAmount == 0) { invoke your method } ....

  3. #3
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: Change text

    Thank you!! How do I write a method that changes/turns the arrow?

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Change text

    Do you have no idea?
    pyl.setText(pyl.getText().equals("-->")?"<--":"-->");

    But in my opinion, it would be better if you would use more OOP. Create classes for the player, scoreboard and so on maybe...

  5. #5
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: Change text

    I tried
    Java Code:
    if(rb%2 == 0)
             {
               
               if(rigting == ("-->")
               {
               pyl.setText("<--");
               }
                pyl.setText("-->");
               }
               }
    hahaha but thanks!!

  6. #6
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Change text

    "..." = strings = objects = you have to compare them by method --> equals!

    Java: ==, .equals(), compareTo(), and compare()

  7. #7
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

Similar Threads

  1. How to change font of text?
    By sandeep43 in forum New To Java
    Replies: 3
    Last Post: 06-30-2011, 06:01 AM
  2. Change text color on type
    By corbokhan in forum New To Java
    Replies: 2
    Last Post: 11-01-2010, 07:30 PM
  3. change syntax text color
    By dejos456 in forum New To Java
    Replies: 5
    Last Post: 12-14-2009, 11:09 AM
  4. change text size in all GUI components
    By itaipee in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2009, 04:59 AM
  5. change Text Colore
    By Mir in forum New To Java
    Replies: 39
    Last Post: 03-26-2009, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •