This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Need help with drawing in a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help with drawing in a JPanel" Watch "Need help with drawing in a JPanel" New topic
Author

Need help with drawing in a JPanel

Ashish Gupta
Ranch Hand

Joined: Apr 27, 2003
Posts: 61
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 ]
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
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

Joined: Apr 27, 2003
Posts: 61
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 ]
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
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.


- Daniel
Ashish Gupta
Ranch Hand

Joined: Apr 27, 2003
Posts: 61
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

Joined: Apr 27, 2003
Posts: 61
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
 
GeeCON Prague 2014
 
subject: Need help with drawing in a JPanel