This is what I have to do: Write an application that asks the user to input the radius of a circle as a floating-point number and draws the circle, as well as the values of the circle's diameter, circumference and area. Use the value 3.14159 for pi. [Note: You may also use the predefined constant Math.PI for the value of pi. This constant is more precise than the value 3.14159. Class Math is declared in the java.lang package, so you need not import it.] Use the following formulas (r is the radius):
diameter = 2r
circumference = 2PIr
area = PI r^2

The user should also be prompted for a set of coordinates in ddition to the radius. Then draw the circle and display its diameter, circumference, and area, using an Ellipse2D.Double object to represent the circle and mehtod draw of class Graphics2D to display it.

code:

``````import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

class Circle extends JComponent{

public Circle(double r)
public void drawCircle(Graphics gr){
Graphics2D g = (Graphics2D)gr;
g.draw(ellipse);
}
public static void main(String[] args) {

double diameter;
double circumference;
double area;
circumference = 2 * Math.PI * radius;
JLabel diameter2 = new JLabel("Diameter: " + diameter);
JLabel circumference2 = new JLabel("Circumference: " + circumference);
JLabel area2 = new JLabel("Area: " + area);

JPanel text = new JPanel(new GridLayout(2,2));
JFrame frame = new JFrame();
frame.setTitle("Draw a Circle");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(true);
}
}
``````

Issues:
It runs, but it doesn't draw the circle. How come?

Also, I want to know where I would put the part that asks for the coordinates? Like would I put it after they enter the radius and how would I set up the coordinate part?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.