Syntax to draw an ellipse:
To draw an ellipse, either any one of the classes need to be used such as “Ellipse2D.Float” and “Ellipse2D.Double” and this class is used based on the ellipse co-ordinates of single or double precision floating values.
Consider the following code to construct an ellipse,
//Fix the co-ordinates and assign it to object “ellip1”
Ellipse2D.Double ellip1=new Ellipse2D.Double(x, y, width, height);
In the above code, the “Ellipse2D.Double” represents that there are two class names “Ellipse2D” and “Double” which is separated by period (.) symbol and it passes four co-ordinates namely “x”, “y”, “width”, and “height”.
Syntax to draw a circle:
To draw a circle, follow the same code but for width and height use the same values. Here, the circle is passed with “x-coordinate”, “y-coordinate”, and “diameter”.
//Fix the co-ordinates and assign it to object “cir1”
Ellipse2D.Double cir1=new Ellipse2D.Double(x, y, diameter, diameter);
//Call draw() to draw the circle
g2.draw(cir1);
Explanation:
- In the above code, “cir1” is the object name of the circle and it passes four parameters such as “x-coordinate”, “y-coordinate”, and “diameter”.
- Next, using the graphics object “g2”, call draw()method to draw the circle.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Big Java, Binder Ready Version: Early Objects
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education