This site requires JavaScript, please enable it in your browser!
Greenfoot back
payner2013
payner2013 wrote ...

2013/11/10

Change colour of text

payner2013 payner2013

2013/11/10

#
ok so i have drawn my text using the following method but how do i change the colour to WHITE?
1
2
3
4
5
6
public Label()
   {
      GreenfootImage img = new GreenfootImage (600, 400);
      img.drawString("hello", 60, 100);
      setImage(img);
   }
Any help will be great, thank you
Zamoht Zamoht

2013/11/10

#
1
2
3
4
5
6
7
public Label()  
   GreenfootImage img = new GreenfootImage (600, 400); 
   img.setColor(java.awt.Color.white);
   img.drawString("hello", 60, 100); 
   setImage(img); 
}
payner2013 payner2013

2013/11/10

#
Thank you very much... worked fine:)
payner2013 payner2013

2013/11/10

#
sorry another question... how can i change the font size and the font its self?
1
2
3
4
5
6
7
public Label()    
{   
   GreenfootImage img = new GreenfootImage (600, 400);   
   img.setColor(java.awt.Color.white); 
   img.drawString("hello", 60, 100);   
   setImage(img);   
}
Zamoht Zamoht

2013/11/10

#
Okay first of all you should import some classes. Go to the top of your class and then under import greenfoot.*; add the following two lines: import java.awt.Color; import java.awt.Font; now change the Label contructor:
1
2
3
4
5
6
7
8
9
10
public Label()      
{     
   GreenfootImage img = new GreenfootImage (600, 400);     
   float fontSize = 36f; //set it to what ever your need
   Font font = img.getFont().deriveFont(fontSize);
   img.setFont(font);
   img.setColor(Color.white);   
   img.drawString("hello", 60, 100);     
   setImage(img);     
}
Should work.
payner2013 payner2013

2013/11/10

#
worked fine thank you:)
You need to login to post a reply.