• 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

Need help with drawing in a JPanel

 
Ranch Hand
Posts: 61
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to draw a graph in a JPanel but am not sure exactly how to achieve this. I have created GUI application and want to add graph as one JPanel in main JPanel there.
Here is the code I have written which works fine standalone.

I was able to find some post in this forum but could not make much out of it.
Also why is the constructor not invoked when I run this file stand alone?
Thanks
Ashish
[ December 03, 2003: Message edited by: Ashish Gupta ]
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a stupid question, but you do know that the constructor above is commented out don't you?
Otherwise I can't see why it isn't called if the code compiles. It is, after all the first line in the main method.
 
Ashish Gupta
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Timmy,
That's a valid question but even if the constructor code is not commented, I did not saw the print statement when I ran standalone. I too expected that constructor will be invoked first before invoking the paint() method. Maybe I am doing somthing really silly.
Since my main question did not really concern that piece of code and I wanted to post my code, I choose to comment it.
If you happen to know answer to my main question, please do help.
Thnaks
Ashish
[ December 04, 2003: Message edited by: Ashish Gupta ]
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you start off your constructor it should read 'public BarGraph()' and not 'public void BarGraph()'. Constructors never return a value so you don't need the 'void' bit.
 
Ashish Gupta
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Daniel,
It was because of the 'void' before the constructor that was causing it not to be invoked. Thanks for pointing out.
About the main question in my original post, I was able to create a JPanel with a graph, but seems there is painting issues, as I don't see a thing.
Thanks
Ashish
 
Ashish Gupta
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I was able to create a JPanel with a graph, but seems there is painting issues, as I don't see a thing.


In case anyone is interested, I was able to see the graph on the JPanel. Trick was

Thanks to those who helped.
Ashish
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic