drawing circle after prompting user
im trying to create a program that prompts the user for the radius, and coordinates t odraw a circle using the Ellipse2D,Double object...
When the user is prompted...how do i take that input and use it in the formula for area, as that also needs to be diplayed when the circle is drawn..
any help..coz i cant get this question right..and im still new to java..:(
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();
final JTextField x = new JTextField();
final JTextField y = new JTextField();
JButton enterButton = new JButton("ENTER");
enterButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
??????
}
}
);
JPanel southPane = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
southPane.add(radius);
southPane.add(enterButton);
}
public void draw(Graphics2D g2)
{
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double circle = new Ellipse2D.Double( x, y, 2*radius, 2*radius);
g2.draw(circle);
}
}
|