Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Change font color

    Well, I must find some time to analyze your code and compile it and then try to find what is wrong, in meantime maybe someone else will come up with solution.

  2. #22
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: Change font color

    Hi,
    you use this modified code... this is working for me.. so you will try this..


    {
    for(int i = 1; i<= 9; i++){
    if(a.getSource() == button[i]){
    button[i].setText("X");
    button[i].setEnabled(true);
    button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
    button[i].setForeground(Color.green);
    }
    }
    }

    else
    {
    for(int i = 1; i<= 9; i++){
    if(a.getSource() == button[i]){
    button[i].setText("O");
    button[i].setEnabled(true);
    button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
    button[i].setForeground(Color.red);
    }

    I think setForeground is works in the time of setEnabled(true) otherwise it is not work..
    Thanks,

  3. #23
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: Change font color

    Hi

    You use this code i hope this will be help to u..
    This is work for me...

    if (turn == 1 || turn==3 || turn==5 || turn==7 || turn== 9)
    {
    for(int i = 1; i<= 9; i++){
    if(a.getSource() == button[i]){
    button[i].setText("X");
    button[i].setEnabled(true);
    button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
    button[i].setForeground(Color.green);
    }
    }
    }

    else
    {
    for(int i = 1; i<= 9; i++){
    if(a.getSource() == button[i]){
    button[i].setText("O");
    button[i].setEnabled(true);
    button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
    button[i].setForeground(Color.red);
    }

    thanks,

  4. #24
    HELPME2 is offline Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0

    Default Re: Change font color

    God bless you bthank you !!

  5. #25
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Change font color

    With setting the button to enabled you will be able to click on it after it already has been chosed. This code worked for me and allowed me to change to whatever color you would like.
    Java Code:
    for(int i = 1; i<= 9; i++){
                   if(a.getSource() == button[i]){
                   button[i].setText("<html><font color = yellow>X</font></html>");
                   button[i].setEnabled(false);
                   button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 5
    Last Post: 05-09-2011, 06:28 AM
  2. Replies: 0
    Last Post: 08-18-2010, 10:31 AM
  3. font color
    By newbie123 in forum New To Java
    Replies: 2
    Last Post: 03-01-2010, 03:58 PM
  4. Replies: 5
    Last Post: 04-25-2009, 08:00 PM
  5. Replies: 0
    Last Post: 06-25-2008, 10:33 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
  •