• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

foreground color

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
This is the question from jaworski mock test. The answer given is D, But I think The answer if C, because the forgroud color is to render the text only.
Am i right..or do anybody wants to make some correction?
Given that the variable g references a valid Graphics
object, what does the following statement do?
g.fillRect(2, 3, 10, 20);
A. draw the outline of a rectangle in the current background
color
B. draw the outline of a rectangle in the current foreground
color
C. fill in a rectangle using the current background color
D. fill in a rectangle using the current foreground color
E. fill in a rectangle in black
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I think, that if you do not set the color of the graphics object ( g.setColor(Color.blue); ) the fill of the object will be black. Can someone confirm this? I don't think that you can set the forground or background color of a graphics object.
Anyone? Anyone?
AJ
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. All drawing is done using the foreground color( aka Pen Color ) and all filling/clearing is done using the background color. This is regardless of whether you are drawing text or image.
Ajith
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
take it this way:
1.when we say drawRec(), it draws a rect with outline black.
2.now if u say fillRec without setting any color to graphics, it fill Rect with black color, so its a sort of foreground.
 
AJ Dussault
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK - conflicting answers to our question??? Anyone have any more comments? A direction where to look? I am reading Core Java Vol 2 and no where do I find any reference to foreground and background as pertaining to a Graphics object and filling a shape. The only thing that I see is setColor. If anyone has any references where I can look to get this information I would appreciate it!!
TIA,
AJ
 
reply
    Bookmark Topic Watch Topic
  • New Topic