P10.7 Write a program that draws a 3D view of a cylinder. 6 public class ChartViewer...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
•• P10.7 Write a program that draws a 3D view of a cylinder. 6 public class ChartViewer 7 { 8 9 10 11 12 13 14 } /** This program displays an editable bar chart. 17 18 19 20 21 public static void main(String[] args) { orked_example_1/ChartFrame.java 22 23 24 } 1 import java.awt.Dimension; 2 import java.awt.event. ActionEvent; 3 import java.awt.event.ActionListener; 4 import javax.swing. JButton; 5 import javax.swing. JFrame; 6 import javax.swing. JLabel; JFrame frame = new Chart Frame(); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; frame.setVisible(true); 7 import javax.swing. JPanel; 8 import javax.swing.JTextField; 9 10 /** 11 12 */ 13 public class ChartFrame extends JFrame 14 { 15 16 A frame that allows users to edit a bar chart. private static final int FRAME_WIDTH = 400; private static final int FRAME HEIGHT = 400; private static final int CHART_WIDTH = 300; private static final int CHART_HEIGHT= 300; private static final String DEFAULT_LABEL private static final double DEFAULT_VALUE = "Description"; = 100; 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 private static final double DEFAULT_VALUE = private JTextField labelField; private JTextField valueField; private JButton addButton; private JButton removeButton; private ChartComponent chart; public ChartFrame() { } chart = new Chart Component(); chart.setPreferredSize (new Dimension (CHART_WIDTH, CHART_HEIGHT)); chart.append (DEFAULT_LABEL, DEFAULT_VALUE); createTextFields (); createButtons (); createPanel(); setSize (FRAME_WIDTH, FRAME_HEIGHT); 100; private void createTextFields () { final int LABEL_FIELD_WIDTH = 20; labelField = new JTextField (LABEL_FIELD_WIDTH); labelField.setText (DEFAULT_LABEL); final int VALUE_FIELD_WIDTH = 10; valueField = new JTextField (VALUE_FIELD_WIDTH); valueField.setText("" + DEFAULT_VALUE); } class AddBarListener implements ActionListener { public void action Performed (ActionEvent event) { String label = labelField.getText (); double value = Double.parseDouble (valueField.getText()); chart.append(label, value); 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 } } } public void createButtons() { } } chart.removeLast (); public void createPanel () { addButton = new JButton("Add"); addButton.addActionListener(new AddBarListener()); removeButton = new JButton ("Remove last"); removeButton.addActionListener(new RemoveBarListener()); e to search JPanel panel= new JPanel(); panel.add (labelField); panel.add (valueField); panel.add (addButton); panel.add (removeButton); panel.add (chart); add (panel); rked_example_1/ChartComponent.java 1 import java.awt.Color; 2 import java.awt.Graphics; 3 import java.util.ArrayList; 4 import javax.swing. JComponent; 5 6 /** A component that draws a chart. 7 8 */ 9 public class Chart Component extends JComponent 10 { stat.D... 발 ■ O 1 import java.awt.Color; 2 import java.awt.Graphics; 3 import java.util.ArrayList; 4 import javax.swing. JComponent; 5 6 7 8 */ 9 public class Chart Component extends JComponent 10 { 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 /** A component that draws a chart. private ArrayList<Bar> bars; private double maxValue; /** */ public Chart Component() { 26 27 28 29 30 31 32 33 34 here to search Constructs an empty chart. } /** bars = new ArrayList<Bar>(); maxValue = 1; } Appends a bar to this chart. @param label the label for the bar @param value the value of the bar */ public void append(String label, double value) { bars.add(new Bar (label, value)); if (value > maxValue) { maxValue = value; } repaint(); A 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 } public void removeLast () { } 10 11 12 13 14 15 16 public void paint Component ( Graphics g). { final int GAP 5; int y = GAP; double scale = getWidth() / maxValue; for (Bar b bars) { } int n = bars.size(); if (n =0) { return; } bars.remove(n - 1); repaint (); } orked_example_1/Bar.java b.draw(g, y, scale); y = y + Bar.HEIGHT + GAP; 1 import java.awt.Color; 2 import java.awt.Graphics; 3 4 /** 5 6 */ 7 public class Bar 8 { 9 A bar of a bar chart. /** private String label; private double value; public static final int HEIGHT = 15; Constructs a bar with a given label and value. Gnaram labol the label for this har 7 public class Bar 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 } private String label; private double value; public static final int HEIGHT = 15; /** Constructs a bar with a given label and value. @param label the label for this bar @param value the value of this bar */ public Bar (String aLabel, double aValue) { label aLabel; value= aValue; } /** } Draws this bar. @param g the Graphics object @param y the top of the bar @param scale the horizontal scale factor for fitting the bar into the component */ public void draw (Graphics g, int y, double scale) { final int GAP = 2; g. fillRect(0, y, (int) (value scale), HEIGHT); g.setColor (Color.WHITE); g.drawstring(label, GAP, y + HEIGHT - GAP); g.setColor (Color.BLACK); •• P10.7 Write a program that draws a 3D view of a cylinder. 6 public class ChartViewer 7 { 8 9 10 11 12 13 14 } /** This program displays an editable bar chart. 17 18 19 20 21 public static void main(String[] args) { orked_example_1/ChartFrame.java 22 23 24 } 1 import java.awt.Dimension; 2 import java.awt.event. ActionEvent; 3 import java.awt.event.ActionListener; 4 import javax.swing. JButton; 5 import javax.swing. JFrame; 6 import javax.swing. JLabel; JFrame frame = new Chart Frame(); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; frame.setVisible(true); 7 import javax.swing. JPanel; 8 import javax.swing.JTextField; 9 10 /** 11 12 */ 13 public class ChartFrame extends JFrame 14 { 15 16 A frame that allows users to edit a bar chart. private static final int FRAME_WIDTH = 400; private static final int FRAME HEIGHT = 400; private static final int CHART_WIDTH = 300; private static final int CHART_HEIGHT= 300; private static final String DEFAULT_LABEL private static final double DEFAULT_VALUE = "Description"; = 100; 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 private static final double DEFAULT_VALUE = private JTextField labelField; private JTextField valueField; private JButton addButton; private JButton removeButton; private ChartComponent chart; public ChartFrame() { } chart = new Chart Component(); chart.setPreferredSize (new Dimension (CHART_WIDTH, CHART_HEIGHT)); chart.append (DEFAULT_LABEL, DEFAULT_VALUE); createTextFields (); createButtons (); createPanel(); setSize (FRAME_WIDTH, FRAME_HEIGHT); 100; private void createTextFields () { final int LABEL_FIELD_WIDTH = 20; labelField = new JTextField (LABEL_FIELD_WIDTH); labelField.setText (DEFAULT_LABEL); final int VALUE_FIELD_WIDTH = 10; valueField = new JTextField (VALUE_FIELD_WIDTH); valueField.setText("" + DEFAULT_VALUE); } class AddBarListener implements ActionListener { public void action Performed (ActionEvent event) { String label = labelField.getText (); double value = Double.parseDouble (valueField.getText()); chart.append(label, value); 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 } } } public void createButtons() { } } chart.removeLast (); public void createPanel () { addButton = new JButton("Add"); addButton.addActionListener(new AddBarListener()); removeButton = new JButton ("Remove last"); removeButton.addActionListener(new RemoveBarListener()); e to search JPanel panel= new JPanel(); panel.add (labelField); panel.add (valueField); panel.add (addButton); panel.add (removeButton); panel.add (chart); add (panel); rked_example_1/ChartComponent.java 1 import java.awt.Color; 2 import java.awt.Graphics; 3 import java.util.ArrayList; 4 import javax.swing. JComponent; 5 6 /** A component that draws a chart. 7 8 */ 9 public class Chart Component extends JComponent 10 { stat.D... 발 ■ O 1 import java.awt.Color; 2 import java.awt.Graphics; 3 import java.util.ArrayList; 4 import javax.swing. JComponent; 5 6 7 8 */ 9 public class Chart Component extends JComponent 10 { 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 /** A component that draws a chart. private ArrayList<Bar> bars; private double maxValue; /** */ public Chart Component() { 26 27 28 29 30 31 32 33 34 here to search Constructs an empty chart. } /** bars = new ArrayList<Bar>(); maxValue = 1; } Appends a bar to this chart. @param label the label for the bar @param value the value of the bar */ public void append(String label, double value) { bars.add(new Bar (label, value)); if (value > maxValue) { maxValue = value; } repaint(); A 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 } public void removeLast () { } 10 11 12 13 14 15 16 public void paint Component ( Graphics g). { final int GAP 5; int y = GAP; double scale = getWidth() / maxValue; for (Bar b bars) { } int n = bars.size(); if (n =0) { return; } bars.remove(n - 1); repaint (); } orked_example_1/Bar.java b.draw(g, y, scale); y = y + Bar.HEIGHT + GAP; 1 import java.awt.Color; 2 import java.awt.Graphics; 3 4 /** 5 6 */ 7 public class Bar 8 { 9 A bar of a bar chart. /** private String label; private double value; public static final int HEIGHT = 15; Constructs a bar with a given label and value. Gnaram labol the label for this har 7 public class Bar 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 } private String label; private double value; public static final int HEIGHT = 15; /** Constructs a bar with a given label and value. @param label the label for this bar @param value the value of this bar */ public Bar (String aLabel, double aValue) { label aLabel; value= aValue; } /** } Draws this bar. @param g the Graphics object @param y the top of the bar @param scale the horizontal scale factor for fitting the bar into the component */ public void draw (Graphics g, int y, double scale) { final int GAP = 2; g. fillRect(0, y, (int) (value scale), HEIGHT); g.setColor (Color.WHITE); g.drawstring(label, GAP, y + HEIGHT - GAP); g.setColor (Color.BLACK);
Expert Answer:
Answer rating: 100% (QA)
Drawing a 3D view of a cylinder requires the use of a graphical library like Matplotlib in Python He... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a program that draws a 3D view of a cylinder.
-
Consider the following function on the given domain.. g(x) = (x + 2) + 1x 2-2 Step 1 of 2: Find a formula for the inverse of the function on the given domain, if possible. Answerow to enter your...
-
On 31 March 1980, Philip acquired a 48-year copyright at a cost of 85,000. The copyright was valued at 92,000 on 31 March 1982. On 31 March 2021, Philip sold the copyright for 47,000. Compute the...
-
Rex became a partner with a 30% interest in the partnership profits when he invested $200,000. In 2016, the partnership generated $400,000 of taxable income, and Rex withdrew $100,000. In 2017, the...
-
The following preliminary unadjusted trial balance of Nevada-For-You Co., a sports ticket agency, does not balance: When the ledger and other records are reviewed, you discover the following: (1) the...
-
The Africa Research Bulletin reported the results of a prefeasibility study by Ironveld plc stating that the grades for pig iron and ferro vanadium were better than expected at its project on the...
-
Under the provisions of the Taft-Hartley Act, which unfair labor practices apply to both unions and employers?
-
At the beginning of the year, Zesty Corporation purchased 10,000 shares of Scrumptious Company common stock for $80 per share. Scrumptious Company, which has issued 40,000 shares of stock, earned net...
-
Briefly explain two intentional torts against persons AND two intentional torts against property? What is due process, and why is it important? In your opinion, should minors be able to avoid their...
-
1.Your client has an asset of USD 1 million with a liability of USD 500,000. 2.The maturity of the liability is 20 years with the yield to maturity of 4%. 3.The client's investment horizon is 3...
-
Recently, you needed money and agreed to sell a car you had inherited at a price of $45,000 , to be paid in monthly payments of $1,300 for 45 months . What (annual) interest rate did you charge for...
-
Adam works as a financial analyst with General Motors. He was asked by his boss to evaluate two potential projects. The initial cost of project 1 is $300,000 and is expected to produce cash flows of...
-
A gear with a radius of 9.0 inches makes 15 revolutions every four seconds. Find the linear and angular velocities of a point on the outer edge of the gear. Give your answers in both exact and...
-
The Geneva mechanism is used in a packaging system to convert constant angular motion into intermittent angular motion. The star wheel A makes one sixth of a revolution for each full revolution of...
-
This proof requires 3 steps. This question is for the third step, line 6. 1. E v F 2. ~ E 3. ~ H / ( F v G ) & ~ H It is probably a good idea to do the proof on paper for yourself, then check the...
-
Determine the values of the given trigonometric functions directly on a calculator. The angles are approximate. tan 0.8035
-
For each of the following situations, calculate the t ratio for a single population correlation coefficient. Identify the critical t value in Table B, and indicate whether the correlation coefficient...
-
Between January 2000 and August 2013, there were 667 arrests of National Football League (NFL) players as reported by Union-Tribune News of San Diego. The table below presents the actual number of...
-
The ANOVA summary table for the Exercise 3 data is presented below. Refer to this information and to the Exercise 3 information to answer the questions. Evaluate statistical significance with alpha...
-
What was the approximate activity of the plutonium source at the start of the mission? A. \(2 \times 10^{21} \mathrm{~Bq}\) B. \(2 \times 10^{19} \mathrm{~Bq}\) C. \(2 \times 10^{17} \mathrm{~Bq}\)...
-
What statement can be made about the masses of atoms in the above reaction? A. \(m\left({ }_{92}^{235} \mathrm{U} ight)>m\left({ }_{56}^{141} \mathrm{Ba} ight)+m\left({ }_{36}^{92} \mathrm{Kr}...
-
Because the decay products in the above fission reaction are neutron rich, they will likely decay by what process? A. Alpha decay B. Beta decay C. Gamma decay The uranium isotope \({ }^{235}...
Study smarter with the SolutionInn App