This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 815
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: 18541
    
    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: 815
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: 18541
    
    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: 24183
    
  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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Draw a cylinder
 
Similar Threads
drawing Cube..
How to find LPG cylinder's expiry date
Attempting Polymorphism...unsuccessfully
Cylindars in Open GL
Keep on rolling