Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2007, 08:20 AM
Authorized User
 
Join Date: May 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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);
     }

}



 
Old June 18th, 2007, 09:19 AM
Authorized User
 
Join Date: May 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, i have done this now..and it is displaying the circle..now how do i prompt the user for the x,y and radius? and then use that input for the details of the circle?
promt the following...
"x coordinate?"
"y coordinate?"
"radius"


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

public class DrawingColor{
  public static void main(String[] args) {
    DrawingColor d = new DrawingColor();
  }

  public DrawingColor(){
    JFrame frame = new JFrame("Drawing with Alpha");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.getContentPane().add(new MyComponent());
    frame.setSize(400,400);
    frame.setVisible(true);
  }

  public class MyComponent extends JComponent{
    public void paint(Graphics g){

      int diameter = 2* 100;

      int x = 0;
      int y = 0;

      Graphics2D g2 = (Graphics2D) g;

      Ellipse2D.Double circle = new Ellipse2D.Double( x, y, diameter, diameter);
      g.setColor(Color.red);
      g2.draw(circle);


     }
  }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Image animation that move in a round circle Andraw Other Programming Languages 7 October 13th, 2008 07:39 AM
Draw Circle using mouse conny Visual C++ 1 September 1st, 2005 05:42 PM
prompting for criteria before printing civa Access VBA 1 March 26th, 2005 10:50 AM
SetTimeout Image Cycling in Circle sasidhar79 Javascript 7 July 3rd, 2004 12:30 AM
prompting user to download files bsatyen Classic ASP Professional 0 September 12th, 2003 02:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.