How to Display a Cylinder in Java

How to Display a Cylinder in Java thumbnail
Java creates different shapes using its own geometrical tool.

Cylinder is a primary geometrical shape that is defined with a height and a radius. But in the Java program, it is a public class. Java is known for its many definitive classes, and producing geometrical shapes has also been addressed by this multifaceted programming language. There are various ways to display a cylinder in Java, but it all starts with the construction of the cylinder.

Instructions

    • 1

      Paste the succeeding codes to construct various cylinders using the Java language:

      public Cylinder()

      The code above constructs a default cylinder with a radius of one inch and a height of two inches. The cylinder's resolution for this element defaults to 15 divisions along its X axis and one along its Y axis.

      public Cylinder(float radius,

      float height)

      The code entered above constructs a default cylinder with a given height and radius. By default, normals are generated but not the texture coordinates. As shown, the parameters used for this cylinder are radius and height.

      public Cylinder(float radius,

      float height,

      Appearance ap)

      The code posted above constructs a default cylinder with a given radius, height, and appearance. By default, normals are generated but not the texture coordinates. As displayed, the parameters for this cylinder are radius, height and "ap," which represents appearance.

    • 2

      Paste the following code to obtain the Shape3D node integrated with the cylinder's given part. This particular method allows users to change the geometry or appearance of specific parts:

      public Shape3D getShape(int partId)

      The parameter used for this code are "partId," which is the part to return (TOP, BODY, or BOTTOM), and the return or response is the Shape3D object integrated with the partId. Nothing will be returned in the partId passed or submitted as invalid.

    • 3

      Paste the following code to get the appearance of the identified part of the cylinder and display it:

      public Appearance getAppearance(int partId)

      The parameter used above is partId, which serves as the identifier for a designated subpart of the cylinder. It will display the appearance of the object integrated with the partId, if the partId submitted is valid -- if the partId is invalid, a null response is returned.

Tips & Warnings

  • To learn more about Java, join discussion forums to ask the expert users some important questions regarding the program. Learn from the tutorials posted online, which include downloadable project samples and complete step-by-step procedures.

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

Related Ads

Featured