File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Draw a cylinder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Draw a cylinder" Watch "Draw a cylinder" New topic
Author

Draw a cylinder

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
What's the easiest way to draw a cylinder within a JPanel? Is there a method similar to drawOval for the Graphics object? Any help would be appreciated. Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Break down the cylinder into its component parts. You already know about drawOval so that's half of the job. I expect you also know about the method required to draw a straight line. Besides that there's just some arithmetic required to figure out where to draw each of the parts.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
Paul,
So no shortcut? :-) I didn't want to go ahead and re-invent the wheel if something already existed. Thanks for the feedback.
RH
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

I haven't checked. You could look at the Graphics documentation for yourself to see if there's drawCylinder or whatever. I just know from experience that people who write APIs don't typically write a ton of convenience methods like that, especially when they just involve simple extensions which anybody could do in a few minutes. You might find that somebody else has written a fancy graphics package which has that ton of convenience methods, though.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

No, there are no methods to draw 2D representations of 3D objects in the core API. There's Java3D, but that's a whole different animal.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Draw a cylinder