Question: Modify this code to draw a 3D cylinder, it needs a some manipulation to look like 3d cylinder import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JFrame; import

Modify this code to draw a 3D cylinder, it needs a some manipulation to look like 3d cylinder

import java.awt.BorderLayout;

import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;

import java.awt.*; import java.applet.*; import java.awt.*; public class Cylinder3D extends Applet {

public void paint(Graphics g) {

int x[]={100,100,140,140}; int y[]={100,160,160,100}; g.setColor(Color.black); g.fillPolygon(x,y,4);

int x1[]={60,60,100,100}; int y1[]={100,160,160,100}; g.setColor(Color.black); g.fillPolygon(x1,y1,4);

g.setColor(Color.gray); g.fillOval(74,100,50,50);

g.setColor(Color.gray); g.fillOval(124,100,50,50);

g.setColor(Color.black); g.drawLine(60,110,140,110);

g.setColor(Color.black); g.drawLine(60,150,140,150); }

public static void main(String[] args) { Cylinder3D c = new Cylinder3D(); JFrame f = new JFrame(); f.add(c); f.setSize(300, 300); f.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

One way to do this is to use the JavaFX library which provides a Cylinder class that can create a 3D ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!