aspose file tools*
The moose likes Java in General and the fly likes draw oval shape Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "draw oval shape" Watch "draw oval shape" New topic
Author

draw oval shape

hadeel marghlany
Greenhorn

Joined: Feb 21, 2013
Posts: 12
i made this class to draw the oval but am not sure if its right and i dont know how to call it in the main

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
That code is well‑nigh illegible because it has not been spaced or indented properly. Please use the button to go back and sort out the code.
You have the wrong arguments for the Ellipse2D constructor. Please look them up.
Delete that empty constructor, unless you particularly want a 0.0×0.0 ellipse.
You cannot call paint unless you have a Graphics object available, which mean on a display/GUI. That method call will never compile in a main method.
Your other method calls will work, but you are not using their return values. Maybe you should print them:- System.out.println(myEllipse.getArea());
Your class names are incorrect; they should be Oval, Shape2D. Only ever use _ in constant names. Don’t write your own PI; use Math.PI.
Never use pow(x, 2). Use x * x.
hadeel marghlany
Greenhorn

Joined: Feb 21, 2013
Posts: 12
please can you explain the graphic part more because its my first time using this library and am totaly lost
hadeel marghlany
Greenhorn

Joined: Feb 21, 2013
Posts: 12
im sorry i thought my code is well sorted and easy to read

the constructers:
the first one is empty beacause it is inherited from a superclass which any way will be added atumaticlly but our professor wanted us to write it

the second constructer should input only two things the short raduis and a long raduis then the
compovalperimeter() and compovalarea() methods take this paramters and calculate it
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
hadeel marghlany wrote:im sorry i thought my code is well sorted and easy to read
Apology accepted (), but the code is not at all easy to read.

the constructers:
the first one is empty beacause it is inherited from a superclass which any way will be added atumaticlly but our professor wanted us to write it

. . .
Constructors are not inherited, and there would be no constructor added automatically. You should query that instruction.

You can only use Graphics if you have a Graphics object. You usually only get a Graphics object on a GUI. You will not be able to put that paint() call in the main method because there is nowhere you can obtain the correct argument.
hadeel marghlany
Greenhorn

Joined: Feb 21, 2013
Posts: 12
so how can i do the draw oval function what library should i use i have read tons of website and tell now i dont know what to do
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
I suggest you read the Java 2D trail.
hadeel marghlany
Greenhorn

Joined: Feb 21, 2013
Posts: 12
i got it thankyou
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: draw oval shape
 
Similar Threads
Hierachies and inheritance
Hierarchies, inheritance, polymorphism and interfaces
Drawing text inside a Graphics2D shape
Graphics2D and Math classes in an Applet
How To Stop Flicking JPanel Component?