promt user for coordinates to draw circle

This program should prompt the user for radius, and coordinates to draw circle. I dont know what to put in " public void actionPerformed(ActionEvent e) " i want it to work out the diameter=2r, circumference = 2(pi)r, area = (pi) r^2 and display the this and the circle...

and i am not sure when to start with the "paintComponent(Graphics g)", i know it is after the coding below? still new at java..and i cant find examples on the web of coding similar to this..

import java.awt.*;

import java.awt.font.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

import javax.swing.text.*;

class SmallCircleTestextends JFrame

{

publicstaticvoid main(String[] args)

{

new SmallCircleTest();

}

public SmallCircleTest()

{

super("SmallCircleTest");

setDefaultCloseOperation(EXIT_ON_CLOSE);

final JTextField radius =new JTextField

return radius;

final JTextField xCoordinate =new JTextField

return xCoordinate;

final JTextField yCoordinate =new JTextField

return yCoordinate;

JButton enterButton =new JButton("ENTER");

enterButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

// HELP?

}

}

[2515 byte] By [Lizanea] at [2007-11-27 8:00:08]
# 1
Try g.drawOval(x, y, width, height);
Jamwaa at 2007-7-12 19:42:03 > top of Java-index,Java Essentials,New To Java...
# 2

this is what i have so far..

where do i put the formulas for area, circumference and area that needs to be displayed aswel..

import java.awt.*;

import java.awt.font.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

import javax.swing.text.*;

class SmallCircleTest extends JFrame

{

public static void main(String[] args)

{

new SmallCircleTest();

}

public SmallCircleTest()

{

super("SmallCircleTest");

setDefaultCloseOperation(EXIT_ON_CLOSE);

final JTextField radius = new JTextField

return radius;

final JTextField xCoordinate = new JTextField

return xCoordinate;

final JTextField yCoordinate = new JTextField

return yCoordinate;

JButton enterButton = new JButton("ENTER");

enterButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

// return x, y and radius

}

}

JPanel southPane = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));

southPane.add(radius);

southPane.add(enterButton);

}

public void paintCircle(Graphics2D g)

{

Graphics2D g2 = (Graphics2D) g;

public void draw(Graphics2D g2)

{

Ellipse2D.Double circle = new Ellipse2D.Double( x, y, 2*r, 2*r);

g2.draw(circle)

}

}

}

Lizanea at 2007-7-12 19:42:03 > top of Java-index,Java Essentials,New To Java...
# 3

Have you had any training in Java, at all?

Have you had any traingin, or experience, in Programming, at all?

I don't ask these to be mean, but to make you look at yourself, because what I am about to say is not going to be nice.

The problems presented in this code cannot be fixed on a Forum. You need to get some training.

You have multiple returns (not conditional) in the same method. That method is a constructor, which BTW, should not have any return at all.

Also, you are returning the JTextFields themselves, rather than using them, in a Dialog, to ask for values, then returning those values. And all of this, once again, should not be done in a Constructor.

Also, the class that actually draws the circle, should, probably, not be the class that asks for the dimensions. It should be created with the proper dimensions by another class that asks for them, with the possibility of redefining those values, once again, by another class.

So, to sum it up, this problem goes much deeper than, where do I put the paintComponent method. This is basic Java, basic Programming, that is lacking.

Once again, I don't mean to be rude or mean, but you need to find a teacher/tutor.

Another possibility, if you think you have the ability to pick it up this way, is to go to http://java.sun.com/docs/books/tutorial/index.html and work your way through the tutorials there. All of them. Starting with "Getting Started" and working your way down the list, even if you think you are past that point in your development. Because, if you are attempting to pick this up on your own, there will be gaps in your basic knowledge, no matter how much of it you think you know.

Once again, sorry to be blunt, but somebody had to do it, I think.

Good Luck. ;-)

masijade.a at 2007-7-12 19:42:03 > top of Java-index,Java Essentials,New To Java...