• 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

paint method

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i am stuck why the following paint method does'nt work!

import java.awt.*;
public class lay2 extends Frame{
public void paint(Graphics g){
g.drawString("i am red",10,10);
g.setColor(Color.red);
}
public static void main(String args[]){
lay2 me =new lay();
me.setSize(5,5,200,200);
me.setVisible(true);
}
}
just an empty frame is visible.please help
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nachiket,
I think your code is working. You just are not drawing the text into a visible position. The X and Y locations in the drawString method specify the lower left position of the text. Since you don't have any characters that have descending parts you are actually drawing off your visible screen. Just change your Y value to 20 or 30 and all should be well!
Regards,
Manfred.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nachiket ,
i think the argumenta that u rapssing to setsize methods r not correct
for setSize method u have to pass only width and height
and for setBounds u have to pass x , y , width and height .
try like this
i think it should work
rahul
 
nachiket deshpande
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred!
i got the string but color is not yet set?
please help.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Give the setColor statement before u draw the string
 
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic